Error using sortrows, too many input arguments

9 次查看(过去 30 天)
Can somebody help me to understand the error? Why do i get it?
Error in zeroup (line 63)
srti(j,3)=sortrows(srt,[1,2],'descend'); %sorted in descending order
for j=1:length(listing(:,3));
srt(j,1)=listing(j,3); %wave height
srt(j,2)=listing(j,4); %wave period
end
srti(j,3)=sortrows(srt,[1,2],'descend'); %sorted in descending order

采纳的回答

Stephen23
Stephen23 2018-12-10
编辑:Stephen23 2018-12-10
sortrows(srt,[-1,-2])
But your allocation does not make much sense:
srti(j,3)=sortrows(srt,...)
because you try to force two columns (the output of sortrows) into one column of srt. How do you expect to force two column into one? Perhaps you just meant to do this:
srt = sortrows(srt,[-1,-2])
  4 个评论
Stephen23
Stephen23 2018-12-10
编辑:Stephen23 2018-12-10
"When i do this it sorts the rows in ascending order as default."
Indeed, ascending is the default.
"How can i convert it to descending order?"
Do either of these things:
  1. Read the sortrows documentation, where it states "Negative integers indicate that the sort order is descending", and then try using negative integers.
  2. Try the code in my answer, which uses negative integers to sort those columns descending.
If that does not give what you expect, then please explain what output you are expecting, together with input and output example arrays to illustrate your explanation.
dj
dj 2018-12-10
Thanks so much for the help, after using negative integers it gives what i want.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by