Filter löschen
Filter löschen

Sorting matrix based on the sum of the rows

6 Ansichten (letzte 30 Tage)
Eunan McShane
Eunan McShane am 9 Jul. 2019
Kommentiert: Eunan McShane am 9 Jul. 2019
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

Akzeptierte Antwort

Akira Agata
Akira Agata am 9 Jul. 2019
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,:);

Weitere Antworten (1)

Bob Thompson
Bob Thompson am 9 Jul. 2019
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.

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by