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

2 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 11 Oct 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.
  2 commentaires
Jesse Finnell
Jesse Finnell le 11 Oct 2019
This is perfect, thanks.
Sulaymon Eshkabilov
Sulaymon Eshkabilov le 11 Oct 2019
You are most welcome. It is just a pleasure.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by