|
"Cat " <c.o'connor@vet.gla.ac.uk> wrote in message <i6dcfq$n8n$1@fred.mathworks.com>...
> Hello everybody,
>
> I'm having a wee problem trying to figure out how to replace all NaN's in my cell array with a value of zero.
>
> A simplified version of my array looks something like this:
> x=
> [1,2,0,4,NaN] [1,2,3,NaN,NaN] [1,5,7,4,NaN] [1,2,0,4,NaN] [1,2,0,4,NaN]
> [NaN,2,0,4,NaN] [1,2,5,5,NaN] [7,2,0,4,NaN] [1,2,0,4,NaN] [1,5,0,4,NaN]
> [1,2,NaN,4,NaN] [7,2,0,4,NaN] [1,5,0,4,NaN] [1,2,0,4,NaN] [5,2,0,4,NaN]
> [1,7,5,5,NaN] [1,NaN,0,4,NaN] [1,2,0,4,NaN] [1,NaN,0,4,NaN] [1,2,7,4,NaN]
> [1,2,0,4,NaN] [NaN,2,0,4,NaN] [NaN,2,NaN,4,NaN] [7,7,0,4,NaN] [1,5,0,4,NaN]
>
> (okay it didn't format correctly but i guess you could get a rough idea)
>
> From looking at answers to similar questions online i've attempted the following solutions:
> x(isnan([x{:}]))={0}
> and
> x(cellfun(@isnan,x))={0}
>
> but neither seem to do what i want.
You might define your own function for this and use cellfun with it. e.g.,
function x = nanzero(x)
x(isnan(x)) = 0;
return
end
cellfun(@nanzero,x,'UniformOutput',false)
James Tursa
|