Another possible solution:
YourCellArray = cellfun(@replaceZeroWithNan,YourCellArray,'UniformOutput',false);
function D = replaceZeroWithNan(D) idx = D == 0; D(idx) = nan; end
Another possible solution:
YourCellArray = cellfun(@replaceZeroWithNan,YourCellArray,'UniformOutput',false);
function D = replaceZeroWithNan(D) idx = D == 0; D(idx) = nan; end
In the generic case, it is not possible to do it without a loop (or cellfun, but in this case, you'd have to use a .m function not an anonymous function:
for idx = 1:numel(yourcellarray) m = yourcellarray{idx}; m(m == 0) = NaN; yourcellarray{idx} = m; end
In your example case, where all the matrices are the same size, then you'd be better off not using a cell array but a 4-D matrix. The replacement is then trivial:
m = cat(4, yourcellarray{:}); m(m == 0) = NaN;
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!