Subplot on a saved figure only working for one subplot
12 次查看(过去 30 天)
显示 更早的评论
I have a figure with three subplots (1 column, 3 rows) that has been pre-allocated with all the formatting and saved.
% allocate figures for saving joint angles per subject
pre_ang_fig = figure();
pre_ax1 = subplot(3,1,1);
ylabel('Ankle angle (\circ)')
set(gca,'TickDir','out')
title('Pre Angles')
pre_ax2 = subplot(3,1,2);
ylabel('Knee angle (\circ)')
set(gca,'TickDir','out')
pre_ax3 = subplot(3,1,3);
xlabel('Gait cycle %')
ylabel('Hip angle (\circ)')
set(gca,'TickDir','out')
saveas(pre_ang_fig,[sub_ext '_' trans_typ '_pre_joint_angles.fig'])
In a loop,I then want to load that figure, and plot some additional data on each subplot, maintaining axis formatting and keeping all data present.
My current code (see below), loads the figure fine and plots perfectly on the third subplot but the first two are remade every time. I have tried using axes instead of subplot but I end up with the exact same result.
pre_ang_fig = openfig([sub_ext '_' trans_typ '_pre_joint_angles.fig']); %load figure
if all_cycles(ii,4) == 1 % if right leg plot right leg data in red
figure(pre_ang_fig)
hold all
subplot(3,1,1)
plot(cycle_norm(:,13),'r') %ankle
subplot(3,1,2)
plot(cycle_norm(:,9),'r') %knee
subplot(3,1,3)
plot(cycle_norm(:,5),'r') %hip
elseif all_cycles(ii,4) == 2 % if left leg, plot left leg data in green
figure(pre_ang_fig)
hold all
subplot(3,1,1)
plot(cycle_norm(:,15),'g') %ankle
subplot(3,1,2)
plot(cycle_norm(:,11),'g') %knee
subplot(3,1,3)
plot(cycle_norm(:,7),'g') %hip
end
saveas(pre_ang_fig, [sub_ext '_' trans_typ '_pre_joint_angles.fig'])
I would like all subplots to look like the bottom subplot here, but instead the first two get overwritten each time and so this is the resulting figure I end up with.
Any help is really appreciated!
0 个评论
回答(1 个)
Sulaymon Eshkabilov
2021-3-31
I presume that you have a loop before "if... end" operations, correct?
You should put "hold all" command after your "plot()" command not after "figure" command.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!