# How to descend order column that have maximum values zero in MATLAB

2 views (last 30 days)
safaa on 31 Mar 2017
Commented: safaa on 31 Mar 2017
For example : A=[ 0 3 2 5 0 3 1 1 2 2; 5 8 6 6 1 0 0 2 3 3; 7 9 9 7 0 0 0 0 0 0; 8 10 10 9 9 8 10 6 5 7;] And column order that have maximum values zero : 5 6 7 1 8 9 10 2 3 4
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

KSSV on 31 Mar 2017
A=[ 0 3 2 5 0 3 1 1 2 2; 5 8 6 6 1 0 0 2 3 3; 7 9 9 7 0 0 0 0 0 0; 8 10 10 9 9 8 10 6 5 7;] ;
[m,n] = size(A) ;
c = zeros(m,1) ;
for i = 1:m
c(i) = n-nnz(A(i,:)) ;
end
[val,idx] = sort(c) ;
A = A(idx,:) ;
##### 1 CommentShowHide None
safaa on 31 Mar 2017
thanks

Sign in to comment.

### More Answers (1)

Thorsten on 31 Mar 2017
[~, idx] = sort(sum(A == 0), 'descend')
##### 1 CommentShowHide None
safaa on 31 Mar 2017
Thanks

Sign in to comment.

### Categories

Find more on Random Number Generation in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!