I cannot plot discontinuous X data.
3 次查看(过去 30 天)
显示 更早的评论
I have the data as shown below.
1.36667 105.403
1.375 105.6288
1.38333 105.8527
1.39167 106.049
11.7 88.2319
11.70833 88.1568
11.71667 88.2712
11.725 88.3003
21.26667 999
21.275 92.3620
21.28333 92.2410
21.29167 92.3133
The x axis expresses time and the y axis shows the observed data.
I try to use the code below to plot dicontinuous data.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data = xlsread('G07.xls');
time = data(:,1);
tec = data(:,3);
max_step = 31/3600;
segends = [find(diff(time) > max_step) length(time)]; % assume x non-decreasing
nsegs = length(segends);
plotargs = cell(3, nsegs);
segend = 0;
for segment = 1:nsegs
segstart = segend+1;
segend = segends(segment);
plotargs{1,segment} = time(segstart:segend);
plotargs{2,segment} = tec(segstart:segend);
plotargs{3,segment} = plotstyle;
end
plot(plotargs{:});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This code works well only one gap data. But the data above has 2 gaps so there is an error message below.
??? Error using ==> horzcat
CAT arguments dimensions are not consistent.
Error in ==> plot_g at 7
segends = [find(diff(time) > max_step) length(time)]; % assume x non-decreasing
I don't know how to fix this problem and how to plot multiple gaps data.
Aike...
0 个评论
回答(3 个)
Walter Roberson
2012-12-9
An easier way to do this, is that at each point you want the break, insert a NaN in both the x and y data. Then use a single plot() call instead of a loop.
0 个评论
Aike
2012-12-10
2 个评论
Image Analyst
2012-12-10
What identifies a "gap"?
And what does 11,680 data points have to do with anything? As I read it you have only 1 file and the data array from that file has 11,680 rows. This is a very small amount of data and you should not worry about the size of it at all. You may think it's large, but trust me - it's not. Far from it.
Walter Roberson
2012-12-10
I didn't say you should insert the NaN manually. You can insert the NaN by way of program. Doing so is easier than maintaining the segments.
Aike
2012-12-10
1 个评论
Walter Roberson
2012-12-10
Start with a data array. Scan backwards from the end. At each point determine whether a gap exists. If it does, insert a NaN at that point, such as
X(K:end+1) = [NaN; X(K:end)];
Y(K:end+1) = [NaN; Y(K:end)];
Keep scanning backwards until you get to the beginning of the array. Then
plot(X, Y);
Just the one plot().
Notice you have no segment arrays, and you plotted it in one statement instead of having to loop doing multiple plots for the same data set. Notice the low probability of dimension problems. Notice too that you had no need of modifying the data files.
After you have tested this out, you can consider even more efficient ways of inserting the NaN if you feel that is worth while.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!