To use the approach you proposed in the question, remove the UniformOutput-property, this way a logical index is returned and the elements can be addressed directly. This works only when the cell content is scalar!
dataC(cellfun(@isinf, dataC)) = {NaN};
Edit: Thanks @Luis Mendo for mentioning, that the use of find is not needed here. My original solution has been dataC(find(cellfun(@isinf,dataC))) = {NaN} and used the unnecessary find in the addressing of dataC.
In case you have arrays in the cells, use the following approach: Write your own function and provide it as a function handle. In the following code I implemented the function replaceInf to do the replacement.
function demo
dataC = ones(2,4); % generate example data
dataC = num2cell(dataC); % convert data to cell array
dataC{2,3} = Inf; % assign an Inf value
dataC{1,2} = [1 2 Inf 3] % add an array to cell
dataC{1,2} % show the cell
dataC = cellfun(@replaceInf, dataC, 'UniformOutput', false)
dataC{1,2} % show the array in the cell
end
function out = replaceInf(in)
in(isinf(in)) = NaN;
out = in;
end
This gives the following output:
dataC =
[1] [1x4 double] [ 1] [1]
[1] [ 1] [Inf] [1]
ans =
1 2 Inf 3
dataC =
[1] [1x4 double] [ 1] [1]
[1] [ 1] [NaN] [1]
ans =
1 2 NaN 3
Infvalues - do you mean the second row ofdataCor the second row ofdataC{k}? i.e. do all the elements ofdataCjust contain scalars? - DanR, and even Excel, do? - Carl Witthoft