does a cell vector contains only NaN?

3 views (last 30 days)
Dear all,
I have
A={
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]
[NaN]}
and I want to find a command that will tell me if A contains only NaN.
I tried
all(isnan(cell2mat(A))), 2) == NaN
but it does not work
cheers

Accepted Answer

Sean de Wolski
Sean de Wolski on 10 Aug 2012
cisnan = @(C)all(cellfun(@(x)all(isnan(x(:))),C));
cisnan(your_cell)

More Answers (1)

Wayne King
Wayne King on 10 Aug 2012
Edited: Wayne King on 10 Aug 2012
There are many ways:
nanarray = cell2mat(cellfun(@isnan,A,'uni',0));
length(nanarray>0)
% the above gives you the answer -- for example
if (length(nanarray>0) > 0)
disp('The cell array contains NaNs')
end

Tags

Community Treasure Hunt

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

Start Hunting!