Plotting with gaps in x-axis data
69 ビュー (過去 30 日間)
古いコメントを表示
I am plotting data against time. The time variable has a uniform sampling rate, but there are times when there may be gaps in the data, for example, when something is powered off. These gaps can be any length of time. When you plot a variable against this time, if there is a gap between two points in time that is greater than the sampling rate, you naturally end up with a plot that has a single line between those two points. Visually, this can be deceiving and can make the gap difficult to identify at first glance, depending on the values of the other variable at those two points. Ideally, I would want to supress the line between those two points, leaving a visual gap. This could obviously be done manually by identifying gaps and then plotting different "chunks" of data with separate commands, but this is not practical beyond a one-off situation. You could potentially create a wrapper around the plot function and choose a time value that identifies gaps in the data that are "too large," plotting "chunks" of data defined in that manner. This would suffer from the use of a static value for that "too large" designation. Does anyone have any good ideas for handling the situation I described, or perhaps seen anything creative out there that would be useful? I realize I'm fighting against the nature of the plot function, but I thought someone else might have already thought of a creative way to address the issue.
Edit:Here's an example of the time vector for reference:
Let's say I have data that is logged at ~1 Hz and the time variable has a range of 10 hours. It might start out like this (I'll assume index 1 is time=0 for ease of dicussion):
[0, 1.00, 2.01, 3.02, 4.01, 5.01, 5.99, 6.98, 7.99, 9.01, 10.00...]
Then you might see a number of gaps of several seconds throughout the 10 hours, maybe a few gaps of several minutes, and a couple gaps of 30 or 45 minutes. Obviously, for the values that are ~1 second apart, I want to connect the data points with a line normally.
Thanks for the help.
Matt
2 件のコメント
回答 (1 件)
KSSV
2020 年 7 月 3 日
It looks like you have a non continuous x-axis data. This problem occurs when you have such data and try to plot.
- Make x-axis data continuous.
- Initiate y-axes data to NaN's equaly in number to x-axis data.
- Use ismemebr to get the existitng values of x-axis data. You can also use setdifference.
- Fill the respective y-axis values with your available data. This will keep NaN's at the missing data.
- Plot the above data. As you have NaN's in the y-axis data and x-axis data is continuous, you will not see a striaght line joining them. You will get gap due to NaN's.
3 件のコメント
KSSV
2020 年 7 月 3 日
That case you decide the time step where you want to give gaps....and make those values NaN's....you need not to give all the values in between nans...to give a gap the end value and first value is nan, it will not get joined while plot.
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!