필터 지우기
필터 지우기

Matlab: problem with connecting points

조회 수: 5 (최근 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 CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by