Matlab multiple curves on same graph

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 5K views
sara_87
Messages
748
Reaction score
0

Homework Statement



Hi all,
I am trying to plot multiple curves in matlab.
If i have the function:
y=x^i

where i goes from 1 to 10.
I want to plot the function y for each i.

Homework Equations





The Attempt at a Solution



x=[1 2 3 4 5 6 7 8 9 10]
for i =1:10
y = x.^i
end
plot(x,y)

this returns 10 sets of the answer y. I want to plot these 10 curves on the same graph.
the above code only plots x against y for the last case (when i=10)

any help would be very much appreciated.
thank you
 
Physics news on Phys.org
sara_87 said:

Homework Statement



Hi all,
I am trying to plot multiple curves in matlab.
If i have the function:
y=x^i

where i goes from 1 to 10.
I want to plot the function y for each i.

Homework Equations


The Attempt at a Solution



x=[1 2 3 4 5 6 7 8 9 10]
for i =1:10
y = x.^i
end
plot(x,y)

this returns 10 sets of the answer y. I want to plot these 10 curves on the same graph.
the above code only plots x against y for the last case (when i=10)

any help would be very much appreciated.
thank you

You can change your code to:

x=[1 2 3 4 5 6 7 8 9 10]
for i =1:10
y(i,:) = x.^i
end
plot(x,y(1,:))
hold on
for i = 2:10
plot(x,y(i,:))
end
hold off