Hold on with subplot in a loop

조회 수: 67 (최근 30일)
Teshome Kumsa
Teshome Kumsa 2022년 5월 15일
편집: Teshome Kumsa 2022년 5월 15일
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

답변 (1개)

VBBV
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
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,
Teshome Kumsa
Teshome Kumsa 2022년 5월 15일
편집: Teshome Kumsa 2022년 5월 15일
Your program is good, but it will not help me if my length (A) is too long. Of course, the reason why I want to replicate figures with as many as the size of my matrix is due to the large amount of data I have to work with. The code I put here is just a sample. It is not my real data. Assume my length (A) is 20. Does it make sense to plot 20 data sets in a single plot?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by