MATLAB Answers

mohamed

i got an error when i run this code ?

Asked by mohamed
on 14 Mar 2013

x=(1:100); for k=1:5 y(:,k)=k*log(x); end plot(x,y)

the error is in the third line? i want to make a single plot for different values of k

  0 Comments

Tags

Products

No products are associated with this question.

2 Answers

Answer by Andrei Bobrov
on 14 Mar 2013
Edited by Andrei Bobrov
on 14 Mar 2013
 Accepted answer
    k = 1:5;
    x = 1:100;
    y = k'*log(x);
    plot(x,y);

  2 Comments

mohamed
on 14 Mar 2013

you really got what i want but did you find the error in my code ??

Andrei Bobrov
on 14 Mar 2013

see Wayne's answer


Answer by Wayne King
on 14 Mar 2013
Edited by Wayne King
on 14 Mar 2013
 x=(1:100); for k=1:5 y(:,k)=k*log(x); end, plot(x,y)

You forgot a semicolon, or comma after end

or better yet:

 x=(1:100); 
 for k=1:5 
   y(:,k)=k*log(x);
 end 
 plot(x,y)

  0 Comments


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today