Sort row by descending error

Hi. I have a cell like this.
A=
'Q7' [ 0]
'Q12H' [-3]
'Q12G' [ 0]
I want to sort by descending direction.
But it says that amaxfc=sortrows(amaxfc,2,'descend');
it says that
Error using sortrows
Too many input arguments.

Respuestas (3)

Walter Roberson
Walter Roberson el 5 de Jul. de 2017

2 votos

The 'descend' option was not added until R2013b. Use
amaxfc = sortrows(amaxfc, -2);
Star Strider
Star Strider el 5 de Jul. de 2017
Try this:
A = {'Q7' [ 0]
'Q12H' [-3]
'Q12G' [ 0]};
amaxfc=sortrows(A,2,'descend')
amaxfc =
3×2 cell array
'Q7' [ 0]
'Q12G' [ 0]
'Q12H' [-3]

3 comentarios

Jonas Lins
Jonas Lins el 31 de Oct. de 2017
I had the same problem as the OP, using 2016b. I am pretty sure that it worked earlier (I have been using that code for a while without touching it). Unfortunately your example does not work either. Walter Robertson's legacy work around does, however. Strange.
Vicki Lewis
Vicki Lewis el 10 de Nov. de 2017
same here on 2016b I get this error
[a,b]=sortrows(data,2,'descend')
Error using sortrows
Too many input arguments.
Star Strider
Star Strider el 11 de Nov. de 2017
I no longer have access to R2016b, so I can’t experiment with it.
Do you have a different variable or function called ‘sortrows’?
See what:
which sortrows -all
reveals.

Iniciar sesión para comentar.

Jan
Jan el 11 de Nov. de 2017
Editada: Jan el 11 de Nov. de 2017

0 votos

According to the documentation of sortrows in R2016b, I see only numerical arrays, CHAR matrices and tables as input, but not cell arrays. But the code works for cells also.
According to the help text and the source code, there are 2 inputs only in R2016b. Therefore the error message is expected and clear.
The 3rd input works only in R2016b, if you apply sortrows to a table object.

Categorías

Más información sobre Environment and Settings en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 5 de Jul. de 2017

Editada:

Jan
el 11 de Nov. de 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by