# title subplots within a for loop

17 views (last 30 days)
Maximilian on 17 Nov 2022
Edited: Voss on 18 Nov 2022
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 on 17 Nov 2022
Moved: Voss on 17 Nov 2022
title(ll + "(m)")
##### 2 CommentsShowHide 1 older comment
Voss on 17 Nov 2022
Edited: Voss on 18 Nov 2022
You're welcome!

Jan on 17 Nov 2022
Edited: Jan on 17 Nov 2022
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
Maximilian on 18 Nov 2022
I have managed to fix the problem.
Thank you

### Categories

Find more on Annotations in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!