Hold on with subplot in a loop
67 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
Hold on, command is messing up my life. I was trying to plot figures using a loop. I want the first two loops in one subplot and the next two loops in another subplot. I tried to hold off and it didn't work.
A={[40;50;60] [70;80;90] [20;30;50]};
B={[45;55;65] [75;85;95] [25;35;55]};
T=[1;2;3];
for i=1:length(A)
figure(i)
subplot(2,1,1)
plot(T,A{i},'-r')
hold on
plot(T,B{i},'--b')
xlabel('x')
ylabel('y')
end
for i=1:length(A)
figure(i)
subplot(2,1,2)
plot(T,cumtrapz(A{i}),'-r')
hold on
plot(T,cumtrapz(B{i}),'--b')
xlabel('xdot')
ylabel('ydot')
end
hold off
for i=1:length(A)
figure(i)
subplot(2,1,1)
loglog(T,A{i},'-y')
hold on
loglog(T,B{i},'--g')
xlabel('ftx')
ylabel('fty')
end
for i=1:length(A)
figure(i)
subplot(2,1,2)
loglog(T,cumtrapz(A{i}),'-y')
hold on
loglog(T,cumtrapz(B{i}),'--g')
xlabel('ftxdot')
ylabel('ftydot')
end
0 comentarios
Respuestas (1)
VBBV
el 15 de Mayo de 2022
Editada: VBBV
el 15 de Mayo de 2022
A={[40;50;60] [70;80;90] [20;30;50]};
B={[45;55;65] [75;85;95] [25;35;55]};
T=[1;2;3];
figure(1) % use this outside of loop
for i=1:length(A)
subplot(2,1,1)
plot(T,A{i},'-r')
title('figure 1')
hold on
plot(T,B{i},'--b')
xlabel('x')
ylabel('y')
end
for i=1:length(A)
subplot(2,1,2)
plot(T,cumtrapz(A{i}),'-r')
hold on
plot(T,cumtrapz(B{i}),'--b')
xlabel('xdot')
ylabel('ydot')
end
hold off
figure(2) % same here too
for i=1:length(A)
subplot(2,1,1)
loglog(T,A{i},'-y')
title('figure ')
hold on
loglog(T,B{i},'--g')
xlabel('ftx')
ylabel('fty')
grid on
end
for i=1:length(A)
subplot(2,1,2)
loglog(T,cumtrapz(A{i}),'-y')
hold on
loglog(T,cumtrapz(B{i}),'--g')
xlabel('ftxdot')
ylabel('ftydot')
grid on
end
2 comentarios
VBBV
el 15 de Mayo de 2022
Use figure outside of loop. you're trying to replicate figure windows with as many as size of your matrix A,
Ver también
Categorías
Más información sobre Subplots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!