Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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

2 vues (au cours des 30 derniers jours)
Zaza
Zaza le 6 Déc 2012
Clôturé : MATLAB Answer Bot le 20 Août 2021
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

Réponses (2)

Matt Fig
Matt Fig le 6 Déc 2012
Modifié(e) : Matt Fig le 6 Déc 2012
See the help for the ISSORTED function.
help issorted

Azzi Abdelmalek
Azzi Abdelmalek le 6 Déc 2012
Modifié(e) : Azzi Abdelmalek le 6 Déc 2012
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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by