Issues Creating Multiple Figures in Same Script

5 次查看(过去 30 天)
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')

采纳的回答

waqas
waqas 2020-7-22
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 个评论
Adrich
Adrich 2020-7-22
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 2020-7-22
编辑:waqas 2020-7-22
Glad to hear that it worked for you.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by