Hold on with subplot in a loop
65 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
VBBV
am 15 Mai 2022
Bearbeitet: VBBV
am 15 Mai 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 Kommentare
VBBV
am 15 Mai 2022
Use figure outside of loop. you're trying to replicate figure windows with as many as size of your matrix A,
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!