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