does a cell vector contains only NaN?

3 visualizzazioni (ultimi 30 giorni)
Sabbas
Sabbas il 10 Ago 2012
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

Risposta accettata

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

Più risposte (1)

Wayne King
Wayne King il 10 Ago 2012
Modificato: Wayne King il 10 Ago 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

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by