How can I assign plotting properties to a subplot within a loop

2 次查看(过去 30 天)
I have this loop to plot some values,
for k = 1:3
figure(1)
subplot(3,1,k)
plot(t{1},A{k})
title('Acceleration v Time 480 CFH')
xlabel('Time (s)')
ylabel('Acceleration (g)')
grid on
%xlim([1 185])
orient(figure(1),'landscape')
print('480CFH Acceleration Open Hole','-dpdf','-fillpage')
end
And I need to apply a set of ylim to the first two subplots and a different set to the third. I tried using something like this,
if k < 3
ylim([-0.2 0.2])
else ylim([-2 0])
end
But this did nothing to the plot. I put this code after the ylabel line.

采纳的回答

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019-10-11
Hi,
You have done well in all steps except for one small point after else condition:
for k = 1:3
figure(1)
subplot(3,1,k)
plot(T{k},F{k})
title('Acceleration v Time 480 CFH')
xlabel('Time (s)')
ylabel('Acceleration (g)')
grid on
%xlim([1 185])
orient(figure(1),'landscape')
print('480CFH Acceleration Open Hole','-dpdf','-fillpage')
if k < 3
ylim([-0.2 0.2])
else
ylim([-2 0])
end
end
Now it is working.
Good luck.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by