How to use a subplot in a for loop
3 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Star Strider
on 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
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!