Sort raw data from a stream, with more zeros on top
Show older comments
I have raw data from a stream, the data is represented like the following N*13 matrix:
% Z Data dE
% _____________ ___________ _____
% 0 0 0 0 0 0 1 2 3 5 2 6 1.0
% 2 1 0 9 0 0 2 5 9 1 8 6 1.5
% 0 0 4 0 0 0 1 2 2 5 9 4 2.0
% 0 0 7 0 1 6 1 6 3 5 1 6 0.1
% 0 0 3 0 1 6 1 2 3 5 7 6 0.4
Rows for whole matrix must be sorted like this:
- Priority to Z, by number of zeros in a descending order (more zeros on top)
- If two lines have same number of zeros in Z, lowest dE has priority (on top)
Considering the example above order should be: 1,3,4,5,2
Accepted Answer
More Answers (1)
dpb
on 25 Apr 2018
>> [~,ix]=sortrows([sum(Z==0,2) dE],[-1 2])
ix =
1
3
4
5
2
>>
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!