How can I sort columns of a matrix based on the order of where the minimums occurs?

8 ビュー (過去 30 日間)
Hello,
I have a column matrix. I want to reorder the columns of the matrix based on the occurence of minimum in each column i.e. the first column should be the one where the minimum value occurs the first, the second where it occurs the second and so on. The attached matrix "id_min" shows this unordered arrangement, for example for column 2 the minimum value is in row 177, so it should be the first column of the new matrix, then column 39 which has the same row 177 for its minimum value, then column 38 whose minimum is in row 179 an so on. The data matrix "aa" is also attached. Your help would be highly appreciated.
Thanks

採用された回答

Matt J
Matt J 2022 年 12 月 21 日
編集済み: Matt J 2022 年 12 月 21 日
Assuming A is your matrix,
[~,imin]=min(A,[],1);
[~,is]=sort(imin);
A=A(:,is);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by