Hello,
I am trying to make a figure with subplots from a for loop. I have been successful, however when I want to assign a title to each run and thus subplot, the figure that matlab is plotting is very strange.
for ll= L(irun)
Ax= z(:,1) + l(1)*z(:,3);
Ay= z(:,2) - l(3)*z(:,3);
figure(10)
hold on
subplot(7,1,irun);
title (ll,"(m)")
hold on
plot(t,Ax)
hold on
plot(t,Ay)
hold on
legend('X Direction (m)', 'Y Direction (m)')
hold on
sgtitle(' Leg A Motion At Different Deck Heights')
end
This is what it is giving me but it should give me the figure below with titiles starting from 20 through to 50. The title below comes from commenting the line:
title (ll,"(m)")
Any advice would be greatly appreciated.
Thank you.

 채택된 답변

Voss
Voss 2022년 11월 17일
이동: Voss 2022년 11월 17일

0 개 추천

How about if you try
title(ll + "(m)")

댓글 수: 2

Maximilian
Maximilian 2022년 11월 17일
이동: Voss 2022년 11월 17일
Great thank you. That worked!
Voss
Voss 2022년 11월 17일
편집: Voss 2022년 11월 18일
You're welcome!

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

추가 답변 (1개)

Jan
Jan 2022년 11월 17일
편집: Jan 2022년 11월 17일

0 개 추천

Avoid the overkill of hold on commands. One per subplot is sufficient.
What is the purpose of the "ll" here:
title(ll,"(m)")
^^
? What does "titles starting from 20 through to 50" mean?
What is irun and L?
for ll= L(irun)
Try this:
for k = 1:7
subplot(7,1,k);
plot(1:10, rand(1, 10));
hold on
title("Plot " + k)
end

댓글 수: 4

Maximilian
Maximilian 2022년 11월 17일
Hello,
ll is a for loop used to assign the title of L for each run . L=20:5:50 and Irun is a for loop with the length of L.
Maximilian
Maximilian 2022년 11월 17일
I have tried to use the code that you sent but it does not seem to work. I would like to title the individal plots 20 meters, 25 meters, 30 meters and so on.
Did you try
figure(10);
for ll= L(irun)
Ax= z(:,1) + l(1)*z(:,3);
Ay= z(:,2) - l(3)*z(:,3);
subplot(7,1,irun);
hold on
plot(t,Ax)
plot(t,Ay)
caption = sprintf('%d meters', ll);
title (caption,"(m)")
legend('X Direction (m)', 'Y Direction (m)')
end
sgtitle('Leg A Motion At Different Deck Heights');
Maximilian
Maximilian 2022년 11월 18일
I have managed to fix the problem.
Thank you

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

카테고리

제품

릴리스

R2022b

태그

질문:

2022년 11월 17일

편집:

2022년 11월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by