Sort matrix of coordinate pairs base of knowledge of adjacent points

4 ビュー (過去 30 日間)
Daniel
Daniel 2024 年 7 月 5 日
回答済み: Umar 2024 年 7 月 5 日
I am currently trying to sort airfoil coordinates and I have tried numerous methods to no avail (bottom edge of trailing edge causes issues). I have set of coordinates [nx2] with column 1 being x and column 2 being y. I have determined the distances to all points from one another ([nxn] matrix) and have obtained the indices of the 2 smallest overall distances for each point. How would I go ordering the original [nx2] matrix based off knowing the indices/coordinates adjacent to each point? ( I have put data for a clark-y airfoil since I am not able to share the airfoil data). Any tips or info will be greatly appreciated!
s1 = [0.97 0.0076868
0.82 0.0400245
0.98 0.0053335
0.02 0.0253735
0 0
0.97 -0.0017011
0.7 0.0614329
0.72 0.0581599
0.92 0.0191156
0.4 -0.0226341
0.86 -0.0057408
0.44 0.0897175
0.88 -0.0050063
0.12 -0.0299633
0.05 -0.0260452
0.1 -0.0293786
0.22 -0.0291445
0.76 -0.0094133
0.06 -0.0271277
0.6 -0.0152893
0.48 -0.0196986
0.05 0.0442753
0.36 0.0916266
0.32 0.0911857
0.92 -0.0035373
0.14 -0.0302404
0.28 0.0900016
0.1 0.0629981
0.56 0.080348
0.012 0.0178581
0.012 -0.0169733
0.94 -0.0028028
0.84 -0.0064753
0.001 -0.0059418
0.4 0.0911712
0.18 0.0810687
0.82 -0.0072098
0.008 0.013735
0.03 0.0330215
0.86 0.031974
0.99 0.002969
0.74 -0.0101478
0.04 -0.0245211
0.99 -0.0009666
0.8 0.0438836
0.9 0.0235025
0.24 -0.0285181
0.02 -0.0202723
0.88 0.0277891
0.2 -0.0296656
0 0
0.002 -0.0078113
0.04 0.0391283
0.64 0.0704822
0.38 -0.0233606
0.62 0.0732055
0.52 0.0842145
0.76 0.0512565
0.22 0.0861433
0.54 0.0823712
0.78 0.0476281
0.68 0.0645843
0.004 0.0089238
0.62 -0.0145551
0.28 -0.0270696
0.16 0.0775707
0.8 -0.0079443
0.7 -0.0116169
0.12 0.0686204
0.24 0.0878308
0.03 -0.0226056
0.72 -0.0108823
0.34 0.0915079
0.008 -0.0142862
0.46 -0.0204353
0.56 -0.0167572
0.9 -0.0042718
0.3 0.0906804
0.46 0.0886427
0.002 0.0058025
0.08 -0.0284595
0.26 0.089084
0.6 0.0757633
0.74 0.0547675
0.42 -0.0219042
0.0005 0.002339
0.38 0.0915212
0.68 -0.0123515
0.84 0.0360536
0.34 -0.0248176
1 -0.0005993
0.004 -0.0105126
0.96 -0.0020683
0.2 0.0839202
0.48 0.0873572
0.58 0.0781451
0.5 0.0858772
0.32 -0.0255565
0.14 0.073436
0.26 -0.0278164
0.36 -0.024087
0.78 -0.0086788
0.3 -0.0263079
0.66 0.0676046
0.0005 -0.00467
0.52 -0.0182262
0.54 -0.0174914
0.5 -0.0189619
0.58 -0.0160232
0.001 0.0037271
0.98 -0.0013339
0.96 0.0100232
0.42 0.0905657
0.94 0.0146239
0.06 0.0487571
1 0.0005993
0.16 -0.0302546
0.18 -0.030049
0.44 -0.0211708
0.64 -0.0138207
0.66 -0.0130862
0.08 0.0564308];
for i = 1:length(s1)
for j = 1:length(s1)
zz = [ (s1(i,1) - s1(j,1));
(s1(i,2) - s1(j,2))];
dist_zz(i,j) = norm(zz);
end
end
ll = [1:length(s1)]';
bb = [ll dist_zz'];
n=2;
for i = 1:length(s1)
b_=sortrows(bb,n,"ascend");
c(:,i)=b_(1);
n=n+1;
end
%% code to order sort s1

回答 (1 件)

Umar
Umar 2024 年 7 月 5 日

Hi Daniel,

You asked, How would I go ordering the original [nx2] matrix based off knowing the indices/coordinates adjacent to each point?

To order the original [nx2] matrix using the adjacent indices or coordinates, you can utilize the sortrows function in MATLAB. This function sorts the rows of a matrix based on specified columns. By specifying the columns corresponding to the adjacent indices, you can achieve the desired sorting. For more information about this function, please refer to

https://www.mathworks.com/help/matlab/ref/double.sortrows.html

I will also provide an example to help you how to use this function.

>> % Original matrix

A = [4 5; 2 3; 1 2; 3 4];

% Sort based on adjacent indices in the first column

sortedA = sortrows(A, 1);

disp(sortedA);

So, in the above code,sortrows(A, 1) sorts matrix A based on the values in the first column. You can adjust the column index according to the adjacent indices you want to use for sorting.

カテゴリ

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

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by