## Could you please tell me why the last part for the descending order isn´t working? Thank you!

Asked by Tobias Schädel

### Tobias Schädel (view profile)

on 8 Jun 2018
Latest activity Commented on by Stephan

### Stephan (view profile)

on 15 Jun 2018
c=[4,5,3;10,30,50;200,900,40]';
c=sortrows(c,1);
d=sortrows(c,3,'descend');

#### 1 Comment

Stephen Cobeldick

### Stephen Cobeldick (view profile)

on 8 Jun 2018
"Could you please tell me why the last part for the descending order isn´t working?"
What does "isn't working" mean? Are you getting an output that you do not expect? (if so what do you expect?) Or is MATLAB throwing an error? (if so, what is the complete error message, and what MATLAB version are you using?)

R2015a

### Stephan (view profile)

on 8 Jun 2018
Edited by Stephan

### Stephan (view profile)

on 8 Jun 2018

Hi,
I will try to guess what you mean:
You want it sorted in ascending order after the first column and descending at the same time after the third column.
If we extend your numerical example a little, then it goes like this:
c=[4,5,3,4,3;10,30,50,40,10;200,900,40,1000,50]
gives
c =
4 10 200
5 30 900
3 50 40
4 40 1000
3 10 50
now:
d = sortrows(c,[1 3],{'ascend', 'descend'})
gives:
d =
3 10 50
3 50 40
4 40 1000
4 10 200
5 30 900
You wanted to do so?
Regardless of whether I have guessed right or wrong, what could be your problem:
Nevertheless, Stephen is absolutely right - The question is very unclear and gives no concrete statement of what your problem is. It is helpful for the volunteers here, if the questions are put as concrete as possible, error messages are attached and if necessary attachments are provided.
Best regards
Stephan

Stephan

### Stephan (view profile)

on 15 Jun 2018
Hi Tobias,
after answering you i saw that Steven Cobeldick gave the better answer - try like he suggested:
d = sortrows(c,[1 -3])
This should give you the result you expect and is much shorter. See Stevens answer below and accept it if you are happy now.
Best regards
Stephan
Tobias Schädel

### Tobias Schädel (view profile)

on 15 Jun 2018
Thanks to all. The commends 'ascend' and 'descend' aren´t working in my version. But this is working.
d = sortrows(c,[1 -3])
Stephan

### Stephan (view profile)

on 15 Jun 2018
Hi Tobias,
fine. In order to help people with similar problems finding helpful answers, please accept S helpful answers.
Best regards
Stephan

### Stephen Cobeldick (view profile)

Answer by Stephen Cobeldick

### Stephen Cobeldick (view profile)

on 8 Jun 2018

Perhaps one of these does what you want:
>> c = [4,5,3;10,30,50;200,900,40]'
c =
4 10 200
5 30 900
3 50 40
>> sortrows(c,[1,-3])
ans =
3 50 40
4 10 200
5 30 900
>> sortrows(c,[-3,1])
ans =
5 30 900
4 10 200
3 50 40