How to sort matrix based on comparison of two rows?
1 view (last 30 days)
Show older comments
i have a matrix 1 2 3 4 5 2 5 6 3 9 4 5 7 8 4 i want to sort the matrix in a way that i want to compare row 2 and row 3 and elemnts of row 2 <row 3 should make a separate matrix and those which are greater makes a different matrix
2 Comments
Shoaibur Rahman
on 24 Dec 2014
Edited: Shoaibur Rahman
on 24 Dec 2014
Could you please rewrite the the matrix? I see it as a vector.
Accepted Answer
Guillaume
on 24 Dec 2014
It's not very clear what you want, possibly this:
m = [1 2 3 4 5
2 5 6 3 9
4 5 7 8 4]; %demo matrix
smaller = m(2, :) < m(3, :); %get a logical array indicating which elements in row 2 are smaller than row 3
msmaller = m(:, smaller); %use logical array to extract columns of m
mgreaterorequal = m(:, ~smaller); %negate logical array to extract the rest of m
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays 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!