Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 11 Okt. 2019
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.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by