- #1
dpsguy
- 69
- 0
I wish to separate the elements of a matrix on the basis of a certain criteria, say, all the elements that are greater than 50 should come at the end, in each row.
For example,
[45 36 78 89 12
54 23 46 71 21
31 41 67 92 19]
should become
[45 36 12 78 89
23 46 21 54 71
31 41 19 67 92]
The important thing here is that the relative order of the elements of a particular type (i.e. those greater or less than 50) should not change. So, in row 2, 54 should still be before 71 after the process is complete.
Assuming that I know the number of elements of each type in each row of the matrix, how do I write a program to accomplish this in MATLAB? I am quite clueless about how to proceed. Any help or suggestions would be most welcome.
For example,
[45 36 78 89 12
54 23 46 71 21
31 41 67 92 19]
should become
[45 36 12 78 89
23 46 21 54 71
31 41 19 67 92]
The important thing here is that the relative order of the elements of a particular type (i.e. those greater or less than 50) should not change. So, in row 2, 54 should still be before 71 after the process is complete.
Assuming that I know the number of elements of each type in each row of the matrix, how do I write a program to accomplish this in MATLAB? I am quite clueless about how to proceed. Any help or suggestions would be most welcome.