Subplot on a saved figure only working for one subplot

조회 수: 19 (최근 30일)
Fernando
Fernando 2021년 3월 31일
답변: Sulaymon Eshkabilov 2021년 3월 31일
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!

답변 (1개)

Sulaymon Eshkabilov
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.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by