How to use a subplot in a for loop

3 visualizaciones (últimos 30 días)
Daniel Porter
Daniel Porter el 21 de Abr. de 2019
Respondida: Star Strider el 21 de Abr. de 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?

Respuestas (1)

Star Strider
Star Strider el 21 de Abr. de 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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by