Let's take some sample data.
x = randi([-10 10], 1, 10);
Change three locations to -999. I also want to make a copy of x to keep around so I can show two techniques and have the original data for comparison.
x(randperm(10, 3)) = -999
x =
-999 -999 -9 -9 4 6 8 7 0 -999
You could use logical indexing.
x(x == -999) = NaN
x =
NaN NaN -9 -9 4 6 8 7 0 NaN
You could also use standardizeMissing.
y = standardizeMissing(xcopy, -999)
y =
NaN NaN -9 -9 4 6 8 7 0 NaN
Now compare the original data and the two modified copies.
[xcopy; x; y]
ans =
-999 -999 -9 -9 4 6 8 7 0 -999
NaN NaN -9 -9 4 6 8 7 0 NaN
NaN NaN -9 -9 4 6 8 7 0 NaN
Best Answer