Azzera filtri
Azzera filtri

How to use a subplot in a for loop

2 visualizzazioni (ultimi 30 giorni)
Daniel Porter
Daniel Porter il 21 Apr 2019
Risposto: Star Strider il 21 Apr 2019
syms y x
y = acos(x);
fplot(y), hold on
for n = [3 5 7]
yk = taylor(y, x, 'Order', n);
fplot(yk), hold on
end
legend('y', 'T3(x)', 'T5(x)', 'T7(x)')
I have the above code which plots my graphs on the same graph but I want them on different graphs but the same figure...how do I do this?

Risposte (1)

Star Strider
Star Strider il 21 Apr 2019
I am not certain what you want.
Try this:
syms y x
y = acos(x);
n = [3 5 7]
ttlc = {'y', 'T3(x)', 'T5(x)', 'T7(x)'};
hold all
subplot(numel(n)+1, 1, 1)
fplot(y)
title(ttlc(1))
for k = 1:numel(n)
subplot(numel(n)+1, 1, k+1)
yk = taylor(y, x, 'Order', n(k));
fplot(yk)
title(ttlc(k+1))
end
hold off

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by