# Create stair plot with uneven spaced data?

10 views (last 30 days)
Cg Gc on 16 Jan 2019
Commented: Cg Gc on 17 Jan 2019
I guess I am over thinking this, but I can't seem to find a solution to my problem.
I have a several columns of variables that represent the mid points of two depths. The depths are not evenly spaced. Some represent 3cm, some 4, others 5 or even 5cm. I would like to create a stair step plot that will handle unevenly spaced depths. See image. Column 1 is my start depth, Column 2 my end depth. Column 3 is the variable to be plotted.
I looked at the stair function and this will create the plot I would like, but I haven't been able to figure out how to use it with user defined spacing that is also uneven.
using the stairs code,
figure; stairs(DepthCopy(1:100,1),DepthCopy(1:100,3))
I come up with this graph, however, the long line between 6 and 6.5 should be a gap as their is no data for this section. It handles the smaller gaps fine when there is a depth but no data, but not when there no depth and no data.
Is my only option to resample the data down to the smallest increment and fill in the fake gaps with NaN?
Any suggestions?

Cg Gc on 16 Jan 2019
Given the complexity of my data set, I gave up trying to figure this out. Instead I resampled the data so that the start and end y values are the same over a certain length determined by the depth values. Basically, I doubled my data length and y samples. It works and can handle the gaps in the data just fine.

Walter Roberson on 16 Jan 2019
It is possible without resampling. Unfortunately I was responding in the middle of my night, and it was escaping me as how best to do it in vectorized fashion, so I headed to bed...
Cg Gc on 17 Jan 2019
No worries. I completely understand the need to sleep. I am accustomed to the large gap in time zones.

### More Answers (1)

Walter Roberson on 16 Jan 2019
When you use stairs() there is no requirement that the x values be evenly spaced.
Supposing your data is in DD:
stairs([DD(1:8,1),DD(8,2)],[DD(1:8,3),DD(8,3)])
hold on
stairs([DD(9:end,1),DD(end,2)],[DD(9:end,3),DD(end,3)])
hold off
You cannot do it as one continuous plot because the right edge of row 8 has a gap of 5 mm before the start of row 9.

Cg Gc on 16 Jan 2019
I tried your code and I got the dreaded horzcat error.
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
How would this work for many more depths? There are over 7000 in one data set and well over 19000 in another.
Walter Roberson on 16 Jan 2019
where I used [DD(something ),DD(something )] use semicolon between the parts.
I pointed out the 5 mm gap and created a second plot to handle it since you were emphasising the importance of the irregularities . Is that gap in fact significant or can we assume that the sections are contiguous or is there some larger gap that is significant while 5mm is not?
Cg Gc on 16 Jan 2019
All gaps are significant. They represent missing data. They vary in size from a few mm to many cm. I like your approach, but identfying all of the gaps in the entire data set is going to be cumbersome. I have 16 variables that can be plotted and several dozen depths.

### Community Treasure Hunt

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

Start Hunting!

Translated by