izaac
izaac

Reputation: 1

How can I plot only a specific range of a curve, while having axis with higher limits?

I need to plot a section of curve, using MATLAB. But I need my axes to be larger than the part I am showing.

For example, I have the following data:

x = 0:50
y = 0.5*x

I would like to plot this data from x=0 to x=20, with xlim([0 50]).

This image should help explain

Just to clarify, I do not want to change the range of values of x, I just want to change what is shown on the graph.

Upvotes: 0

Views: 2614

Answers (2)

Ita
Ita

Reputation: 303

Do this:

x = 0:20
y = 0.5*x
plot(x,y)
xlim([0 50]) % This will set x-axis to the desired range
ylim([min(y) max(y)])

Upvotes: 0

Cris Luengo
Cris Luengo

Reputation: 60444

Say you have some data

x = 0:50;
y = 0.5*x;

and you would like to plot only a part of it, say everything where x<=20. You can do as follows:

index = x <= 20;
plot(x(index), y(index))
xlim(x([1,end])) % set the x-axis limit to the range of all your `x` values
ylim([min(y),max(y)]) % set the y-axis limit to the range of all your `y` values

Upvotes: 1

Related Questions