MATLAB: Replacing -999 in a table to NaN regardless of the type of the column

replacetable

Hi,
I have table Final with -999 and -9999 representing missing values (Data attached). I would like to replace these -999 with NaN regardless of the type of the column (double or string).I tried
Final= convertvars(Final, @isnumeric, @no999);
function x = no999(x)
x(x==-999) = nan;
end
But still it shows -999 values. Any hint about how to do it?

Best Answer

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 = 1×10
-999 -999 -9 -9 4 6 8 7 0 -999
xcopy = x;
You could use logical indexing.
x(x == -999) = NaN
x = 1×10
NaN NaN -9 -9 4 6 8 7 0 NaN
You could also use standardizeMissing.
y = standardizeMissing(xcopy, -999)
y = 1×10
NaN NaN -9 -9 4 6 8 7 0 NaN
Now compare the original data and the two modified copies.
[xcopy; x; y]
ans = 3×10
-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