does a cell vector contains only NaN?

3 Ansichten (letzte 30 Tage)
Sabbas
Sabbas am 10 Aug. 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

Akzeptierte Antwort

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

Weitere Antworten (1)

Wayne King
Wayne King am 10 Aug. 2012
Bearbeitet: Wayne King am 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!

Translated by