MATLAB: How to replace numbers (-999) for NaN in a dataset

datasetnanreplace

Hi,
I have a large dataset with variables containing -999. I want to change those numbers to NaN but it is not working…
I2=find(Dataset==-999); Dataset(I2)=NaN;
…this is the error I get:
Undefined operator '==' for input arguments of type 'dataset'.
Thank you for your help!

Best Answer

Note: datasets have been deprecated for a while. Consider using tables instead.
A dataset is a collection of variables. So you have to do your replacement per variable. e.g.
yourdataset.somevariable(yourdataset.somevariable == -999) = nan;
%same for all variables
Another option would be to use replacedata. For it to work you'll have to create an m file for a replacement function:
function X = datasetreplace(X)
X(X == -999) = nan;
end
You can then do:
newdataset = replacedata(yourdataset, @datasetreplace)