Prev: Newton-Raphson
Next: Best fit with conditions
From: Ioannis Mitsos on 18 Jan 2010 07:21 Hello, Lets say that I have the matrix: NN=[ 1 2 3 4 1 9 3 5 9 2 9 3] which are coordinates on a 3d system. What I want to do is to sort them in an ascending order according to the value of the elements of the first column. So the result will be: NN=[1 2 3 2 9 3 3 5 9 4 1 9]; Does anybody have an idea how to do it?
From: Jan Simon on 18 Jan 2010 07:35 Dear Ioannis! > NN=[ 1 2 3 > 4 1 9 > 3 5 9 > 2 9 3] > > which are coordinates on a 3d system. What I want to do is to sort them in an ascending order according to the value of the elements of the first column. So the result will be: > > NN=[1 2 3 > 2 9 3 > 3 5 9 > 4 1 9]; [dummy, SortIndex] = sort(NN(:, 1)); NNsorted = NN(SortIndex, :) Good luck, Jan
From: Jos (10584) on 18 Jan 2010 07:53 "Ioannis Mitsos" <ioannis-mitsos(a)hotmail.com> wrote in message <hj1jnf$cdu$1(a)fred.mathworks.com>... > Hello, > > Lets say that I have the matrix: > > NN=[ 1 2 3 > 4 1 9 > 3 5 9 > 2 9 3] > > which are coordinates on a 3d system. What I want to do is to sort them in an ascending order according to the value of the elements of the first column. So the result will be: > > NN=[1 2 3 > 2 9 3 > 3 5 9 > 4 1 9]; > > Does anybody have an idea how to do it? > help sortrows Jos
From: Ioannis Mitsos on 18 Jan 2010 08:05 "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hj1khp$4p9$1(a)fred.mathworks.com>... > Dear Ioannis! > > > NN=[ 1 2 3 > > 4 1 9 > > 3 5 9 > > 2 9 3] > > > > which are coordinates on a 3d system. What I want to do is to sort them in an ascending order according to the value of the elements of the first column. So the result will be: > > > > NN=[1 2 3 > > 2 9 3 > > 3 5 9 > > 4 1 9]; > > [dummy, SortIndex] = sort(NN(:, 1)); > NNsorted = NN(SortIndex, :) > > Good luck, Jan Jan it works perfectly!!I really appreciate your help!!Thanks a lot ;-) cheers, Ioannis
From: Jan Simon on 18 Jan 2010 12:31
Dear Jos! > > NN=[ 1 2 3 > > 4 1 9 > > 3 5 9 > > 2 9 3] > > > > NN=[1 2 3 > > 2 9 3 > > 3 5 9 > > 4 1 9]; > > help sortrows The given example does not distinguish between SORTROWS or SORT of first line. The OP has to define what should happen for: NN=[ 1 2 3 4 2 9 4 1 9 3 5 9 2 9 3] What is the last row then? SORTROWS: [4 2 9], because it is "greater" than [4 1 9] SORT(1st column): [4 1 9], because it is "later" in the input. Kind regards, Jan |