Point not match and connect with the nearest point to line

조회 수: 3 (최근 30일)
TAN SAK JIE
TAN SAK JIE 2021년 5월 27일
편집: TAN SAK JIE 2021년 5월 30일
Point not match and connect with the nearest point to line
The data I exported from the ANSYS FLUENT...and when i plot it the line is not follow the black dot but connect in the zig zag direction.. Any one can fix it :(
I wish to know how to rearrange the data so that the i can match the nearest black dot to plot a line in order to erase the unwanted data
  댓글 수: 5
Jan
Jan 2021년 5월 28일
This is not trivial. If the point is preferred, which changes the direction of the former trajectory as small as possible, then the corner at x=0.25 will be a problem:
So you need a smart algorithm, which considers the nearest point, if it is near enough, but decides for another point, if the trajectory is straight enough. For 2D and 3D surfaces Matlab offers the alphaShape , but I do not know the command for a line.
How are the positions of the dots calculated? The creator does not know, that this is a connected graph. Otherwise it should be trivial to output the coordinates in the correct order directly.
Image Analyst
Image Analyst 2021년 5월 28일
Are you willing to simply hand draw a dividing line through the right and left portions?

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2021년 5월 28일
편집: Jan 2021년 5월 28일
To my surprise finding the nearest point iteratively solves the problem already:
[x,y] = nearestConnection(a.Topwall(:,2), a.Topwall(:,3));
plot(x, y)
function [xa, ya, index] = nearestConnection(x, y)
xa = zeros(size(x));
ya = zeros(size(y));
index = zeros(size(x));
% Find the initial point defined by the smallest X value:
[~, idx0] = min(x);
xa(1) = x(idx0);
ya(1) = y(idx0);
index(1) = idx0;
x(idx0) = NaN; % Mask original point
y(idx0) = NaN;
for k = 2:numel(x)
dist = (x - xa(k - 1)) .^ 2 + (y - ya(k - 1)) .^ 2;
[~, idx] = min(dist);
index(k) = idx;
xa(k) = x(idx);
ya(k) = y(idx);
x(idx) = NaN;
y(idx) = NaN;
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Pulse and Transition Metrics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by