Issues Creating Multiple Figures in Same Script

12 views (last 30 days)
Hello, I'm looking to create a series of figures in a script, each figure should have multiple plots in it. I cannot seems to get the behavior I'm looking for however.
I've tried to use 'hold on' and 'hold off' but the script appears to completely ignore this and just throw every plot into the same figure seemingly any time I invoke "hold" at all. Adding some axes and trying to separate them that way has resulted in a perfect figure if I run it only for a single figure, but a mess with overlaid axes and titles with no data in it if I try to run all three. The current code I'm using to try and generate the figures is below. Any help would be appreciated.
position_1 = a1_sol.a0 + 0*t + a1_sol.a2*t^2 + a1_sol.a3*t^3
position_2 = a2_sol.a0 + 0*t + a2_sol.a2*t^2 + a2_sol.a3*t^3
pathq1 = subs(position_1);
pathq2 = subs(position_2);
axis1 = axes;
hold(axis1,'on')
fplot(axis1,pathq1,[0,5])
fplot(axis1,pathq2,[0,5])
title('Joint Positions vs Time')
hold(axis1,'off')
velocity_1 = diff(position_1);
velocity_2 = diff(position_2);
velq1 = subs(velocity_1);
velq2 = subs(velocity_2);
axis2 = axes;
hold(axis2,'on')
fplot(axis2,velq1,[0,5])
fplot(axis2,velq2,[0,5])
title('Joint Velocities vs Time')
hold(axis2,'off')
acceleration_1 = diff(velocity_1);
acceleration_2 = diff(velocity_2);
accq1 = subs(acceleration_1);
accq2 = subs(acceleration_2);
axis3 = axes;
hold(axis3,'on')
fplot(axis2,accq1,[0,5])
fplot(axis2,accq2,[0,5])
title('Joint Accelerations vs Time')
hold(axis3,'off')

Accepted Answer

waqas
waqas on 22 Jul 2020
Wouldn't the following make more sense?
position_1 = a1_sol.a0 + 0*t + a1_sol.a2*t^2 + a1_sol.a3*t^3
position_2 = a2_sol.a0 + 0*t + a2_sol.a2*t^2 + a2_sol.a3*t^3
pathq1 = subs(position_1);
pathq2 = subs(position_2);
figure
subplot(3,1,1)
fplot(axis1,pathq1,[0,5])
hold on
fplot(axis1,pathq2,[0,5])
title('Joint Positions vs Time')
hold off
velocity_1 = diff(position_1);
velocity_2 = diff(position_2);
velq1 = subs(velocity_1);
velq2 = subs(velocity_2);
subplot(3,1,2)
fplot(axis2,velq1,[0,5])
hold on
fplot(axis2,velq2,[0,5])
hold off
title('Joint Velocities vs Time')
acceleration_1 = diff(velocity_1);
acceleration_2 = diff(velocity_2);
accq1 = subs(acceleration_1);
accq2 = subs(acceleration_2);
subplot(3,1,3)
fplot(axis2,accq1,[0,5])
hold on;
fplot(axis2,accq2,[0,5])
title('Joint Accelerations vs Time')
hold off
  2 Comments
Adrich
Adrich on 22 Jul 2020
The code I posted above is the result of a ton of debugging and experimenting, my original code looks much like what you posted.
The code you posted does fix my issue though (with some minor tweaks), so thanks! It appears my misunderstanding was where to put "hold on" - that is, right after the first fplot is created and not before like I was doing.
waqas
waqas on 22 Jul 2020
Edited: waqas on 22 Jul 2020
Glad to hear that it worked for you.

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!