Error using sortrows, too many input arguments
조회 수: 10 (최근 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
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
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:
- Read the sortrows documentation, where it states "Negative integers indicate that the sort order is descending", and then try using negative integers.
- 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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!