MATLAB: Replace NaN values with blanks

nanreplace

Hello all,
I need to replace the NaN values with a blank space in either a matrix or cell array. What should I do?? On trying the below code with cell array, I got the following error:
a(cellfun(@isnan,a)) = {[]}; Error: Function name must be a string.
I am using Matlab 7.0.1 (R14).
How should I give the isnan function???
Thanks in advance for the help.

Best Answer

R14 is very old now. I'm not sure if cellfun accepted function handles freely in this version. But you can emulate this simply by a loop:
for k = 1:numel(C)
if isnan(C{k})
C{k} = '';
end
end
Replacing NaN values by '' in a matrix will not work: All elements of a matrix need to be the same type. While NaN is a double or single, the empty string is a char.