Sorting matrix based on the sum of the rows

15 ビュー (過去 30 日間)
Eunan McShane
Eunan McShane 2019 年 7 月 9 日
コメント済み: Eunan McShane 2019 年 7 月 9 日
I am trying to sort the matrix 'counts' (attached as csv) so that the sum of the rows increases to the 512th pixel so that I have effectively lowest sum to highest sum in order
Thank you

採用された回答

Akira Agata
Akira Agata 2019 年 7 月 9 日
Like this?
% Read data from CSV
A = csvread('Counts.csv');
% Calculate order vector (pt) based on sum(A,2)
[~,pt] = sort(sum(A,2));
% Sort the matrix
B = A(pt,:);
  1 件のコメント
Eunan McShane
Eunan McShane 2019 年 7 月 9 日
Perfect, thank you!

サインインしてコメントする。

その他の回答 (1 件)

Bob Thompson
Bob Thompson 2019 年 7 月 9 日
A = randi(100, 10, 10);
sums = sum(A,2);
[~,I] = sort(sums);
B = A(I',:);
There may be a better way of doing this, but this is the first thing that came to mind. Just replace A with your data.

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by