Sorting cell array based on distance
이전 댓글 표시
I have two cell arrays that contain information about the x,y,z coordinates for points in space. These data are random and do not necessarily follow any sequence.
Example of data1:
-512.7269 -223.8000 -256.1018
-509.1519 -223.8000 -263.4274
-512.9410 -223.8000 -256.3643
-508.8008 -223.8000 -263.5808
-521.0831 -223.8000 -263.1835
-520.0226 -223.8000 -259.8741
-505.0888 -223.8000 -251.5124
-504.7663 -223.8000 -251.4452
Example of data2:
-500.2925 -178.0828 -260.5501
-500.3713 -177.7340 -259.0459
-500.4465 -177.1616 -257.6118
-500.5162 -176.3785 -256.2803
-500.5790 -175.4029 -255.0823
-500.6334 -174.2572 -254.0454
-500.6780 -172.9680 -253.1935
-500.7120 -171.5645 -252.5458
I am trying to sort the data so that the nearest points in space appear in the same sequence of rows.
This is how the code looks like so far. It calculates the minimum distance for combination of every 2 points and then sort this distance in an ascending fashion. What is missing is the part that updates 'data1' to follow the same sequence.
data1 = importdata ('nodes.txt')
Xi = data1(:,1);
Yi = data1(:,2);
Zi = data1(:,3);
data2 = importdata ('TT_angleBlock_nodes.csv')
Xt = data2(:,1);
Yt = data2(:,2);
Zt = data2(:,3);
input = [Xi,Yi,Zi];
output= [Xt,Yt,Zt];
for row = 1 : 1:row
deltaX = output(row,1) - input(:,1);
deltaY = output(row,2) - input(:,2);
deltaZ = output(row,3) - input(:,3);
% Pythagorean Theorem
distances = sqrt(deltaX .^2 + deltaY .^ 2 + deltaZ .^ 2);
minDistance(row) = min(distances);
Dist = sort (minDistance);
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!