Matlab: problem with connecting points

4 visualizzazioni (ultimi 30 giorni)
yoni verhaegen
yoni verhaegen il 27 Mar 2017
Modificato: Walter Roberson il 28 Mar 2017
Hello all,
I have a dataset with points (X,Y coordinates) that represent the shape of a glacier. However, when I plot them with
% Import glacier shape
Glaciershape = readtable('dem_glacierlocation.txt');
figure(1);
S = Glaciershape(:,1);
T = Glaciershape(:,2);
plot(S,T,'-')
It seems that an points connect when they don't need to (see attachment, at the left upper corner of the shape). Is there a way to fix this? I uploaded the dataset as an attachment.
Thanks!
  1 Commento
KSSV
KSSV il 28 Mar 2017
You need to understand the file format....file has X and Y, below X and Y there two data points separated by comma? And in between some were the values are not given.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 28 Mar 2017
Modificato: Walter Roberson il 28 Mar 2017
readtable() cannot read that file, as it uses comma as the decimal separator. To read the data you need
Glaciershape = cell2mat( textscan( regexprep( fileread('dem_glacierlocation.txt'), ',', '.'), '%f %f', 'HeaderLines', 1, 'Collectoutput', 1) );
which will give you an N x 2 numeric array.
The problem you are observing with your data is that those unwanted lines are really there in your data. Your input has no indication of "draw or slew" -- that is, no indication of whether each point should be connected to the previous or next point. Your map tries to represent three disconnected coastlines without using any indication of disconnection. It does that by just reaching one point, continuing over to the first point of the first disconnected region, drawing the complete first disconnected region, continuing on to the first point of the second disconnected region, and continuing on.
You need to find the break-points in the data. One of them is near row end-200 and the other is near row end-94 . Best would be if what you had in your file marked them explicitly as breakpoints; without matters get a bit tougher.
Perhaps you could search for the places where the distance between adjacent points was greater than some threshold, and declare that was a discontinuity.

Categorie

Scopri di più su Geoscience in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by