Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

i got an error when i run this code ?

Asked by mohamed

mohamed

on 14 Mar 2013
Accepted Answer by Andrei Bobrov

Andrei Bobrov

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

mohamed

mohamed

Tags

Products

No products are associated with this question.

2 Answers

Answer by Andrei Bobrov

Andrei Bobrov

on 14 Mar 2013
Edited by Andrei Bobrov

Andrei Bobrov

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

2 Comments

mohamed

mohamed

on 14 Mar 2013

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

Andrei Bobrov

Andrei Bobrov

on 14 Mar 2013

see Wayne's answer

Andrei Bobrov

Andrei Bobrov

Answer by Wayne King

Wayne King

on 14 Mar 2013
Edited by Wayne King

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

Wayne King

Wayne King

Contact us