MATLAB R2023a: Trouble with handling NaN values in mixed numeric and cell arrays
I've searched everywhere and can't find a clear answer. I'm currently working with an scenario while processing a mixed array in MATLAB R2023a that contains both numeric values and cell strings. My goal is to replace any NaN values in the numeric part with a default value, while leaving the cell strings untouched. However, after trying to implement this, I'm getting unexpected results. Here's what I have so far: ```matlab data = {1, 2, NaN, 'test'; 4, NaN, 6, 'example'; NaN, 8, 9, 'demo'}; default_value = 0; % Attempt to replace NaNs for i = 1:size(data, 1) for j = 1:size(data, 2) if isnumeric(data{i, j}) && isnan(data{i, j}) data{i, j} = default_value; end end end ``` After executing this code, I expected to see all NaN values replaced with 0, but the output remains unchanged for the numeric entries. The values in the cell array are still NaN, and I am unsure why the condition for `isnumeric` is not working as expected. I've also tried using `cellfun`, but it seems to complicate things further. Is there a better approach to handle this scenario? Any insights on how to correctly identify and replace NaN values within a mixed array would be greatly appreciated! For context: I'm using Matlab on macOS. Is there a better approach? For context: I'm using Matlab on Linux.