how to find a block containing NaN in cell

hi sir,i have cell of 10*10 cell which look like below double <5x10 double> <5x10 double> <5x10 double> <5x10 double> <5x10 double> <5x10 double> <5x10 double> <5x10 double>
i have to find in which 5x10 double NaN is present

1 Comment

The description of the data is not clear. Please post some code, which create a relevant set of test data - with small arrays.

Sign in to comment.

 Accepted Answer

A={[1 nan 2] [1 3 5] [nan nan 7] [9 7 2]}
out=cellfun(@(x) any(any(isnan(x))),A)

2 Comments

thank you so much
A more general solution could be independent of the array dimensions:
out = cellfun(@(x) any(isnan(x(:))), A);

Sign in to comment.

More Answers (1)

Perhaps:
x = {1:5, 2:6, [3,4,NaN,6,7]};
hasNaN = false(size(x));
for ix = 1:numel(x)
hasNaN(ix) = any(isnan(x{ix}));
end
A CELLFUN could do this also, but a loop is easier to understand and fast to write. Please explain at first if my guess matches your data.

1 Comment

its great answer...bt i m getting error as In an assignment A(:) = B, the number of elements in A and B must be the same. In the cell that u ve given, has one row in each block.but in the cell which i ve has 5*10 elements in each block.this may be the reason....could u please resolve

Sign in to comment.

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!