order the rows of the 3 matrices starting from the third coordinate of the point P
2 ビュー (過去 30 日間)
古いコメントを表示
Hi! I have to order the rows of the 3 matrices starting from the third coordinate of the point P.
A = [28.0445 -17.2717 83.972 1 2 3
27.8199 -16.986 83.3748 4 5 6
27.2756 -16.339 81.871 7 8 9
25.3805 -14.0329 67.019 10 11 12];
B = [25.3805 -14.0329 67.019 13 14 15
25.3425 -14.0698 66.0921 16 17 18
25.2731 -14.1203 65.1073 19 20 21
25.1719 -14.1617 64.1436 22 23 24];
C = [25.3805 -14.0329 67.019 25 26 27
26.2863 -14.4669 67.2675 28 29 30
27.0031 -14.7142 67.6157 31 32 33
27.7458 -14.9233 68.1745 34 35 36];
P = [25.3805 -14.0329 67.019];
So the final result would be:
A_new = [25.3805 -14.0329 67.019 10 11 12
27.2756 -16.339 81.871 7 8 9
27.8199 -16.986 83.3748 4 5 6
28.0445 -17.2717 83.972 1 2 3];
B_new = [25.3805 -14.0329 67.019 13 14 15
25.3425 -14.0698 66.0921 16 17 18
25.2731 -14.1203 65.1073 19 20 21
25.1719 -14.1617 64.1436 22 23 24]; % same as B
C_new = [25.3805 -14.0329 67.019 25 26 27
26.2863 -14.4669 67.2675 28 29 30
27.0031 -14.7142 67.6157 31 32 33
27.7458 -14.9233 68.1745 34 35 36]; % same as C
P = [25.3805 -14.0329 67.019];
2 件のコメント
採用された回答
Dyuman Joshi
2023 年 10 月 5 日
編集済み: Dyuman Joshi
2023 年 10 月 5 日
Use sort
A = [28.0445 -17.2717 83.972 1 2 3
27.8199 -16.986 83.3748 4 5 6
27.2756 -16.339 81.871 7 8 9
25.3805 -14.0329 67.019 10 11 12];
B = [25.3805 -14.0329 67.019 13 14 15
25.3425 -14.0698 66.0921 16 17 18
25.2731 -14.1203 65.1073 19 20 21
25.1719 -14.1617 64.1436 22 23 24];
C = [25.3805 -14.0329 67.019 25 26 27
26.2863 -14.4669 67.2675 28 29 30
27.0031 -14.7142 67.6157 31 32 33
27.7458 -14.9233 68.1745 34 35 36];
P = [25.3805 -14.0329 67.019];
%Sort according to distance from the 3rd coordinate of P
[~,idx1]=sort(abs(A(:,3)-P(3)));
[~,idx2]=sort(abs(B(:,3)-P(3)));
[~,idx3]=sort(abs(C(:,3)-P(3)));
A_new = A(idx1,:)
B_new = B(idx2,:)
C_new = C(idx3,:)
0 件のコメント
その他の回答 (1 件)
Fabio Freschi
2023 年 10 月 5 日
If you want to sort A according to the third column you can simply do the following
% your data
A = [28.0445 -17.2717 83.972 1 2 3
27.8199 -16.986 83.3748 4 5 6
27.2756 -16.339 81.871 7 8 9
25.3805 -14.0329 67.019 10 11 12];
B = [25.3805 -14.0329 67.019 13 14 15
25.3425 -14.0698 66.0921 16 17 18
25.2731 -14.1203 65.1073 19 20 21
25.1719 -14.1617 64.1436 22 23 24];
C = [25.3805 -14.0329 67.019 25 26 27
26.2863 -14.4669 67.2675 28 29 30
27.0031 -14.7142 67.6157 31 32 33
27.7458 -14.9233 68.1745 34 35 36];
% engine
[~,idx] = sort(A(:,3))
A_new = A(idx,:);
similarly for B and C
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!