Sorting matrix based on the sum of the rows

7 次查看(过去 30 天)
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 个)

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 CenterFile Exchange 中查找有关 Shifting 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