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!