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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Plot for two range of x

Asked by pallav pal on 15 Feb 2013

I have two ranges of x = [0:0.01:1] and x = [2:0.01:3] and I want to plot x vs. Y in one plot for the two rages of x values without using hold on command. Is it possible in matlab?

Below I have used hold on command (which I don't want to use) to plot

x = [0:0.01:1]
Y = x./5;  
plot(x, Y, 'Color',[0.85 0.16 0], 'linewidth', 2);
hold on
x = [2:0.01:3]
Y = x./5;  
plot(x, Y, 'Color',[0.85 0.16 0], 'linewidth', 2);

0 Comments

pallav pal

Tags

Products

No products are associated with this question.

2 Answers

Answer by Honglei Chen on 15 Feb 2013
Accepted answer

Something like this?

x = [0:0.01:1 nan 2:0.01:3]
y = x./5
plot(x,y)

1 Comment

pallav pal on 15 Feb 2013

Yes I want this exactly. Thank you very much. Where to see the details about nan ?

Honglei Chen
Answer by Jos (10584) on 15 Feb 2013

Or still separate them in different graphic objects:

    x1 = [0:0.01:1] ;
    y1 = x1./5;  
    x2 = [2:0.01:3] ;
    y2 = x2./5;  
    plot(x1, y1, '-', x2,y2,'-', 'Color',[0.85 0.16 0], 'linewidth', 2) ;

0 Comments

Jos (10584)

Contact us