how to sort a matrix based on a specific value and bring the row at the beginning of the file
Show older comments
Hi all, i want to do a strange sort into my file. I have a file which contains values like:
100 200 x1
201 340 x2
341 400 x4
405 460 x1
461 500 x5
501 600 x1
etc
I want in a way to search for the rows that in their 3rd column have the value x1 and then put the whole row at the beginning of the file. So as an output i d like to have something like:
100 200 x1
405 460 x1
501 600 x1
201 340 x2
341 400 x4
461 500 x5
any ideas? thanks in advance.
Accepted Answer
More Answers (1)
Roger Stafford
on 10 Jul 2014
Edited: Roger Stafford
on 10 Jul 2014
If you put that data in a single matrix M, the 'sortrows' function will do what you want:
M = sortrows(M,3);
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!