I cannot plot discontinuous X data.

1 次查看(过去 30 天)
Aike
Aike 2012-12-9
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...

回答(3 个)

Walter Roberson
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.

Aike
Aike 2012-12-10
Yes, Walter Roberson, However, I have around 11,680 data so I cannot insert NaN to every files one by one.
  2 个评论
Image Analyst
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
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
Aike 2012-12-10
Sorry, I didn't make it clear. The data above comes from parts of the GPS data from one GPS satellite (G07). In fact there are 32 GPS satellites for one day. That means I have 32 files for each day. For all data, I have to analyze one year data so I have 32*365 = 11,680 files for one GPS receiver in one year. Actually, there are around 1000 GPS receivers from GEONET over Japan so I cannot insert NaN to 11,680*1000 GPS files.
For the data gap, I mean the discontinuous x data which expresses Time in my data. The x data below was shown in universal time (UT).
1.36667 1.375 1.38333 1.39167
11.7 11.70833 11.71667 11.725
21.26667 21.275 21.28333 21.29167
The data is discontinuous, 1 UT --> 11 UT --> 21 UT The code on M.file above can plot only 1 UT --> 11 UT. In the case of 1 UT --> 11 UT --> 21 UT, there is an error with the program. Thus, I need some help to plot whole data.
Thank you very much for all kindly reply messages.
Regards, Aike...
  1 个评论
Walter Roberson
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by