How to eliminate the lines that joins the discontinued points in a data?

60 views (last 30 days)
Hi
I have matrices 'lat' and 'lon' of dimensions 1x8646, that forms basically the ground track of a satellite. There are many discontinuities in the data points and also appear on the plot. I want to eliminate the lines in the plot that joins the discontinuities. This joining of discontinuity makes the plot in appropriate.
Could someone guide me how to eliminate those joints?
is there any command in matlab that can determine the discontinuity in data? or the indices of those points in a matrix where the data discontinues?
Thanks in advance
zohaib
  3 Comments
Syed Zohaib Ali
Syed Zohaib Ali on 3 Nov 2012
By 'discontinuity' I mean
e.g I have lat= [ 35.47 35.51 35.54 35.58 35.61 49.23 49.25 49.26 49.28......] and lon= [ 48.91 48.95 49.00 49.04 49.09 72.77 72.84 72.91 72.97......]
if you notice the 6th element in both above vectors are changed as in 'lat' it changed from 35.61 to 49.23.
so on plotting, a line joins the points (35.61,49.09) and (49.23, 72.77). that is what i dont want.
I hope you will be able to understand.
Image Analyst
Image Analyst on 3 Nov 2012
Did you not want to try my solution for some reason? Take another look at it. I even edited it to use the sample data you supplied.

Sign in to comment.

Accepted Answer

Jonathan Epperl
Jonathan Epperl on 4 Nov 2012
Edited: Jonathan Epperl on 4 Nov 2012
How about this:
lat= [ 35.47 35.51 35.54 35.58 35.61 49.23 49.25 49.26 49.28];
lon= [ 48.91 48.95 49.00 49.04 49.09 72.77 72.84 72.91 72.97];
tol = 1; % distance > tol indicates discontinuity
dl = diff([lat;lon],1,2); % look up what that command does if you don't know it
euler_dist = sqrt((dl(1,:)+dl(2,:)).^2); % distance between data points
jumpind = [0 euler_dist>tol]; % now if jumpind(i) = true, we know that the
% point [lat(i) lon(i)] is the first after a jump
blocks = cumsum(jumpind); % points that belong to the same continuous part
% have the same value in blocks
% Now just loop over the continuous blocks to draw a separate line for each one
for i=0:blocks(end)
plot(lat(blocks==i),lon(blocks==i),'LineWidth',2);
hold on;
end
hold off
[EDIT] If you wanted to do it "right", you'd have to use the great circle distances between two points, but I hope above method is robust enough
  3 Comments
Image Analyst
Image Analyst on 4 Nov 2012
I haven't heard of that Euler distance, and could not find mention of it except where people seem to calculate the Euclidean distance but call it the Euler distance by mistake. Perhaps there is such a thing (like it's the length of the Euler lines or something) - I don't know. What you gave is the Euclidean distance and it looks like that would work just as well.
But your data is still all crammed into two very tiny clusters when you plot them on the same plot (like I mentioned in my answer). Is that OK for you?
Jonathan Epperl
Jonathan Epperl on 5 Nov 2012
Haha, yes and yes. I miswrote and credited it Euler when I meant Euclid, and yes, the distance is also computed the wrong way, it should be
euler_dist = sqrt( dl(1,:).^2 + dl(2,:).^2 );
As for the different axes, my impression was that this was just some arbitrary sample data and not the OP's real data, but I'm sure he could adapt either code to his needs anyway.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 3 Nov 2012
Edited: Image Analyst on 3 Nov 2012
You might be able to identify the discontinuities by thresholding and then replace them with nans so they don't show up during plotting.
lowValidLat = 10; % or whatever the lowest lat you want to consider is.
highValidLat= 60; % or whatever the highestlat you want to consider is. badLats = lat < lowValidLat | lat > highValidLat;
lat(badLats) = nan;
same for the lons.
It would help if you uploaded a screenshot so we can see what you're dealing with, or post some sample data.
You might want to look at deleteoutliers
[EDIT] Put in your sample data
lat= [ 35.47 35.51 35.54 35.58 35.61 49.23 49.25 49.26 49.28]
lon= [ 48.91 48.95 49.00 49.04 49.09 72.77 72.84 72.91 72.97]
subplot(2,2,1);
plot(lat, lon, 'bs-');
title('All Lats', 'FontSize', 20);
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Plot the low values.
lowValidLat = 30; % or whatever the lowest lat you want to consider is.
highValidLat= 40; % or whatever the highestlat you want to consider is.
badLats = lat < lowValidLat | lat > highValidLat;
lat(badLats) = nan;
subplot(2,2,2);
plot(lat, lon, 'bs-');
title('Low Lats', 'FontSize', 20);
grid on;
% Plot the high values.
lowValidLon = 60; % or whatever the lowest lat you want to consider is.
highValidLon= 100; % or whatever the highestlat you want to consider is.
badLons = lon < lowValidLon | lon > highValidLon;
lon(badLons) = nan;
subplot(2,2,3);
plot(lon, lon, 'bs-');
title('High Lons', 'FontSize', 20);
grid on;
  2 Comments
Jonathan Epperl
Jonathan Epperl on 4 Nov 2012
I think the OP wanted to eliminate the line between two points that are too far apart -- what you are doing seems to eliminate points that are outside of a certain region.
Image Analyst
Image Analyst on 4 Nov 2012
Edited: Image Analyst on 4 Nov 2012
Yes, Exactly. But you can't just set the endpoints to nan to eliminate the connecting line because that would get rid of a segment in the two valid regions to the right and left of the discontinuity (the usual trick people use to not plot things). That's why I extracted each side of the discontinuity. Your code does essentially the same thing, identifying each segment with the "blocks" array. I plotted them separately because each segment was so tiny that when plotted on the same axis, you could not see them, but of course you could if you wanted to (though I don't know why you wouldn't want to see the data). You plotted them all on the same plot so each "block" would be really tiny so that you can't really see what's going on in them, but this is the way the Syed did it so maybe he doesn't care about viewing/resolving data in those tiny clusters.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!