Got Questions? Get Answers.
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

Thread Subject:
How to stop interpolation of the Matlab 'PLOT' function?

Subject: How to stop interpolation of the Matlab 'PLOT' function?

From: Aaronne

Date: 22 Dec, 2011 18:19:08

Message: 1 of 6

I have got a problem about Matlab 'PLOT' function.

Assume we have
    a = [1 2 3];
and we plot it.
    plot(a);

This will display a straight line; however, if I want to draw something like a 'step'. How to avoid the interpolation from the Matlab 'PLOT' function.

Another example is I have got a 'rect' function f(x)=1 when |x|<=2, otherwise, it is zero. I would like to plot it. However, matlab PLOT connect the points 2 and 3 with a linear interpolation, which is not good...

Any ideas would be appreciated. Thanks.
Aaronne.

Subject: How to stop interpolation of the Matlab 'PLOT' function?

From: someone

Date: 22 Dec, 2011 18:45:09

Message: 2 of 6

"Aaronne" wrote in message <jcvsas$j3m$1@newscl01ah.mathworks.com>...
> I have got a problem about Matlab 'PLOT' function.
>
> Assume we have
> a = [1 2 3];
> and we plot it.
> plot(a);
>
> This will display a straight line; however, if I want to draw something like a 'step'. How to avoid the interpolation from the Matlab 'PLOT' function.
>
> Another example is I have got a 'rect' function f(x)=1 when |x|<=2, otherwise, it is zero. I would like to plot it. However, matlab PLOT connect the points 2 and 3 with a linear interpolation, which is not good...
>
> Any ideas would be appreciated. Thanks.
> Aaronne.

doc stairs

Subject: How to stop interpolation of the Matlab 'PLOT' function?

From: Matt J

Date: 22 Dec, 2011 18:48:08

Message: 3 of 6

"Aaronne" wrote in message <jcvsas$j3m$1@newscl01ah.mathworks.com>...
> I have got a problem about Matlab 'PLOT' function.
>
> Assume we have
> a = [1 2 3];
> and we plot it.
> plot(a);
>
> This will display a straight line; however, if I want to draw something like a 'step'. How to avoid the interpolation from the Matlab 'PLOT' function.
>
> Another example is I have got a 'rect' function f(x)=1 when |x|<=2, otherwise, it is zero. I would like to plot it. However, matlab PLOT connect the points 2 and 3 with a linear interpolation, which is not good...
==================

Just sample the thing you're plotting at a higher resolution, e.g.,

>> t=1:.0001:3; plot(t,round(t))
>> x=-3:.001:3; plot(x, abs(x)<2)

Subject: How to stop interpolation of the Matlab 'PLOT' function?

From: Aaronne

Date: 22 Dec, 2011 19:04:09

Message: 4 of 6

Thanks.

How about this problem.

I have got some data

dy = [0.1 0.1 0.1 0.2 0.2 0.2 0.3 0.3 0.3 0.5 0.5 0.45 0.45 0.45 0.45];
x = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15];

I want to plot data dy as y-axis values with coordinates x. I want to show it like the combination of step functions.


Aaronne.

Subject: How to stop interpolation of the Matlab 'PLOT' function?

From: Matt J

Date: 22 Dec, 2011 19:27:08

Message: 5 of 6

"Aaronne" wrote in message <jcvuv9$rmn$1@newscl01ah.mathworks.com>...
> Thanks.
>
> How about this problem.
>
> I have got some data
>
> dy = [0.1 0.1 0.1 0.2 0.2 0.2 0.3 0.3 0.3 0.5 0.5 0.45 0.45 0.45 0.45];
> x = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15];
>
> I want to plot data dy as y-axis values with coordinates x. I want to show it like the combination of step functions.
=================


In what way is this different from your earlier problem? (Why wouldn't STAIRS apply just as before?)

Subject: How to stop interpolation of the Matlab 'PLOT' function?

From: Aaronne

Date: 22 Dec, 2011 19:45:09

Message: 6 of 6

Great! STAIR is the solution.

Merry Christmas!
Aaronne.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us