How can I organize the rows of an array in a specific order?
1 次查看(过去 30 天)
显示 更早的评论
Good morning. I have the following problem. I have a square matrix of N * N (The matrix can be of different size), in the final row of said matrix there are some indices in a certain order, these indices are also in the final column of the matrix but in a different order. What I want is a code that allows me to organize the rows of the matrix in the same order as the final row of the matrix. The purpose of this is to obtain a symmetric matrix.
Example.
Before organizing:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/273570/image.jpeg)
After organizing:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/273571/image.jpeg)
Thank you very much for your help.
0 个评论
采纳的回答
Sai Sri Pathuri
2020-2-28
Let the square matrix of order NxN be A. In order to obtain symmetric matrix from A, you may try the following:
Sort the elements in the last row of matrix A and get the indices (Ir) of sorted elements
[Sr,Ir] = sort(A(N,:)
Similarly, sort the elements in the last column of matrix A and get indices Ic
[Sc,Ic] = sort(A(:,N)')
Now align the rows of matrix according to the last row of matrix A by
A(Ir,:)= A(Ic,:)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 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!