Matlab: problem with connecting points

4 ビュー (過去 30 日間)
yoni verhaegen
yoni verhaegen 2017 年 3 月 27 日
編集済み: Walter Roberson 2017 年 3 月 28 日
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 件のコメント
KSSV
KSSV 2017 年 3 月 28 日
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.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 3 月 28 日
編集済み: Walter Roberson 2017 年 3 月 28 日
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.

カテゴリ

Help Center および File ExchangeGeoscience についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by