MATLAB: Replace NaN with zeros for several variables in a dataset

nannan datasetreplace nan

I have a large dataset with many variables containing NaN. I want to change all the NAN to 0 at once but I've not been able to do so. For instance, for A < 1000000 x 50 dataset> I've tried the following: >> x=find(isnan(A)); which does not work b/c 'isnan' is not defined for datasets
The following works but I have to do it variable by variable >> x=find(isnan(A.VarName)); >> A.VarName(x)=0; I also try to use a loop but have not succeeded.
Any suggestion on how to changes NAN for all dataset at once or for a set of numeric variables at once. Thanks Vasquez

Best Answer

If A is your dataset
B=double(A);
B(isnan(B))=0;
replacedata(A,B)
Or
B=dataset2cell(A)
B(cellfun(@isnan,B))={0}
replacedata(A,B(2:end,:))