does a cell vector contains only NaN?

3 visualizaciones (últimos 30 días)
Sabbas
Sabbas el 10 de Ag. de 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

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 10 de Ag. de 2012
cisnan = @(C)all(cellfun(@(x)all(isnan(x(:))),C));
cisnan(your_cell)

Más respuestas (1)

Wayne King
Wayne King el 10 de Ag. de 2012
Editada: Wayne King el 10 de Ag. de 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

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by