Create stair plot with uneven spaced data?

3 次查看(过去 30 天)
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.
Capture9.JPG
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.
Capture7.JPG
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
Cg Gc 2019-1-16
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.
  2 个评论
Walter Roberson
Walter Roberson 2019-1-16
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
Cg Gc 2019-1-17
No worries. I completely understand the need to sleep. I am accustomed to the large gap in time zones.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2019-1-16
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.
  3 个评论
Walter Roberson
Walter Roberson 2019-1-16
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
Cg Gc 2019-1-16
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by