Sort Matrix by Columns (descending by the number NaN entries)

Once again I need your help!
I have a matrix with a variable number of columns. All these columns have a different number of NaN entries.
I would like to sort the matrix in a way that I have a new matrix with the first column having the lowest number of NaN entries,...
Thanks a lot in advance!

 Accepted Answer

A=rand(10);ii=randperm(100);A(ii(1:40))=nan %example
[c,idx]=sort(sum(isnan(A)))
out=A(:,idx)

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!