Plotting discontinuos X Data

1 view (last 30 days)
Moiz
Moiz on 2 Jan 2016
Answered: Mike Garrity on 4 Jan 2016
I have a data set that looks like this :
datax = [6 7 8 9 14 48 49 50 55 87 88 89];
datay = [1 1 1 1 2 3 3 3 4 5 5 5];
I want to make a single figure which will have essentially 5 lines corresponding to every jump in the x data. The first line will be ones reperesenting X index 1:4 i.e, 6,7,8,9 The second line will be a single point at 2 representing X index 5 i.e, 14 The third line will be threes representing X index 6:8 i.,e 48,49,50 and so on. Also the code should be extendable to any datax with discontinuities like shown above and produce a new line at every discontinuity.

Accepted Answer

Mike Garrity
Mike Garrity on 4 Jan 2016
You can use nan to represent discontinuities:
datax = [6 7 8 9 nan 14 nan 48 49 50 55 nan 87 88 89];
datay = [1 1 1 1 nan 2 nan 3 3 3 4 nan 5 5 5];
plot(datax,datay,'-o')

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!