Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

how can i determine whether a matrix of any size is sorted or not (by rows and by columns)?

조회 수: 2 (최근 30일)
Zaza
Zaza 2012년 12월 6일
마감: MATLAB Answer Bot 2021년 8월 20일
suppose i have A = [1 2 3 4; 5 6 7 8] is sorted
but A = [1 2 3 4; 5 6 8 7] is not
diff(A) returns "1"-s mtrix if columns are sorted

답변 (2개)

Matt Fig
Matt Fig 2012년 12월 6일
편집: Matt Fig 2012년 12월 6일
See the help for the ISSORTED function.
help issorted

Azzi Abdelmalek
Azzi Abdelmalek 2012년 12월 6일
편집: Azzi Abdelmalek 2012년 12월 6일
out1=all(arrayfun(@(x) issorted(A(x,:)),1:size(A,1))) % by rows
out2=all(arrayfun(@(x) issorted(A(:,x)),1:size(A,2))) % by columns

태그

Community Treasure Hunt

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

Start Hunting!

Translated by