How can I sort a matrix elementwise ?
2 ビュー (過去 30 日間)
古いコメントを表示
Gayan Lankeshwara
2019 年 10 月 21 日
コメント済み: Gayan Lankeshwara
2019 年 10 月 21 日
Hi, I need to sort a matrix elementwise and get the results to a single vector without losing the index of each element.
For example,
A = [3, 4 ; 6, 2]
The sorted vector should be ,
B = [2;3;4;6]
without losing the information of each and every element in the original matrix.
Thank you.
0 件のコメント
採用された回答
Andrei Bobrov
2019 年 10 月 21 日
A = [3, 4 ; 6, 2];
[m,~] = size(A);
[B,i] = sort(A(:));
index = [mod(i-1,m) + 1, ceil(i/m)];
参考
カテゴリ
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!