How to replace numbers (-999) for NaN in a dataset?
4 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Guillaume
on 12 Mar 2018
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)
See Also
Categories
Find more on Data Preprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!