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 (view profile)

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

mohamed

mohamed (view profile)

Tags

Products

No products are associated with this question.

2 Answers

Answer by Andrei Bobrov

Andrei Bobrov (view profile)

on 14 Mar 2013
Edited by Andrei Bobrov

Andrei Bobrov (view profile)

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

2 Comments

mohamed

mohamed (view profile)

on 14 Mar 2013

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

Andrei Bobrov

Andrei Bobrov (view profile)

on 14 Mar 2013

see Wayne's answer

Andrei Bobrov

Andrei Bobrov (view profile)

Answer by Wayne King

Wayne King (view profile)

on 14 Mar 2013
Edited by Wayne King

Wayne King (view profile)

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 (view profile)

Contact us