Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matlab plot jump discontinuity [duplicate]

Tags:

plot

matlab

Is it possible to plot a sequence of data without interpolating them? I would like to keep the value of one data point until the value of the next one.

So for example:

I have my time vector

time = [1 2 3 4 5 6]

and datapoints =[3 0 1 4 5 6]

I would like that the line of my plot is 3 from time(1) till time(2) and then it should change in time(2) to take the value 0. Basically in correspondence of the time 2 my plot should assume both the value 3 and 0 (jump discontinuity)...

I hope I was clear.

like image 239
gabboshow Avatar asked Mar 14 '26 09:03

gabboshow


1 Answers

A short answer: yes you can.

Use the stairs() function.

time=[1 2 3 4 5 6];
datapoints = [3 0 1 4 5 6];

stairs(time,datapoints)

Good luck!

like image 90
EJG89 Avatar answered Mar 15 '26 23:03

EJG89