MATLAB: Remove rows or cols whose elements are all NaN

colsnanrows

How can I remove rows or cols whose elements are all NaN ? Withouot any dirty iterations?
For example,
A = [1 1 1 1 1 1 1 1 1 1;
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN;
1 1 1 1 1 1 1 1 1 1;
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN;];
should turned into
A = [1 1 1 1 1 1 1 1 1 1;
1 1 1 1 1 1 1 1 1 1];
This is just an example. Actually I have a very big matrix. So I want a solution of this question to work well with my big matrix.

Best Answer

out = A(all(~isnan(A),2),:); % for nan - rows
out = A(:,all(~isnan(A))); % for nan - columns