Hold on with subplot in a loop
조회 수: 67 (최근 30일)
이전 댓글 표시
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
답변 (1개)
VBBV
2022년 5월 15일
편집: VBBV
2022년 5월 15일
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
VBBV
2022년 5월 15일
Use figure outside of loop. you're trying to replicate figure windows with as many as size of your matrix A,
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!