Sorting matrix based on the sum of the rows
조회 수: 9 (최근 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
댓글 수: 0
채택된 답변
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
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.
댓글 수: 0
참고 항목
카테고리
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!