lets assume I have the following array:
a = {1; 'abc'; NaN}
Now I want to find out in which indices this contains NaN, so that I can replace these with ” (empty string).
If I use cellfun with isnan I get a useless output
cellfun(@isnan, a, 'UniformOutput', false)
ans =
[ 0]
[1x3 logical]
[ 1]
So how would I do this correct?
Indeed, as you found yourself, this can be done by
Breakdown:
will return a logical scalar, irrespective of whether
xis a scalar or vector.Using this function inside
cellfunwill then erradicate the need for'UniformOutput', false:These can be used as indices to the original array:
which in turn allows assignment to these indices:
Note that the assignment must be done to a cell array itself. If you don’t understand this, read up on the differences between
a(inds)anda{inds}.