how i can replace (99999,9) and (99,9900) in a column by NAN?

1 view (last 30 days)
this file consists of 6 columns: the the third,the fourth,the fifth and the sixth include values such as (99999,9) and (99,9900) ; these values i want to replace them by the following word (NAN) not a number.....please tell me the code for doing this...........the name of the file is space......the name of the third column is y3......the name of the fourth column is y4........the name of the fifth column is y5......the name of the sixth column is y6.. i hope you tell me the code for replacing 99999,9 and 99,9900 by NAN (not a number).
  1 Comment
astrogeophysicist mohamed
astrogeophysicist mohamed on 26 Mar 2020
this file consists of 6 columns: the the third,the fourth,the fifth and the sixth include values such as (99999,9) and (99,9900) ; these values i want to replace them by the following word (NAN) not a number.....please tell me the code for doing this...........the name of the file is space......the name of the third column is y3......the name of the fourth column is y4........the name of the fifth column is y5......the name of the sixth column is y6.. i hope you tell me the code for replacing 99999,9 and 99,9900 by NAN (not a number).

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 26 Mar 2020
Edited: Cris LaPierre on 26 Mar 2020
I'd use the function standardizeMissing.
% Create a row vector and replace all instances of -99
% with the standard missing value for double data types, NaN.
A = [0 1 5 -99 8 3 4 -99 16];
B = standardizeMissing(A,-99)
  7 Comments
Cris LaPierre
Cris LaPierre on 26 Mar 2020
You must be trimming the header lines out of your file. If I run that code on the space.txt file attached to this question, I get the following error message:
Error using load
Unable to read file 'space.txt'. Input must be a MAT-file or an ASCII file containing numeric data with same number of columns in each row.
Cris LaPierre
Cris LaPierre on 26 Mar 2020
Once your data is in MATLAB, use standardizeMissing to replace the specified value with NaN. You'll need to do this for each variable. Here is the code for y3.
y3 = standardizeMissing(y3,99999.9);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!