Replace a specific text value in a table with NaN

3 views (last 30 days)
I've got a table generated from importing *.csv data.
Some of the values in the table read as 'NOVALUE' and I would like to replace them all by NaN. The table can have various sizes (both in number of columns and rows), so the rule will have to apply to the entire table wherever a 'NOVALUE' is found.
I've tried a few examples with table2array and == but none seems to work in this specific case.
Image Analyst
Image Analyst on 27 Jun 2022
Would the whole column be NOVALUE like you showed, or might some of the other elements have a value.
Would you rather just delete the entire column?
Can you attach one of your CSV files with the paperclip icon after you read this:

Sign in to comment.

Answers (1)

Chandrika on 27 Jun 2022
As per my understanding, you want to standardize the missing values in the table. We can do this using 'TreatAsMissing'. You can try using the following code for the same:
data= readtable("Filename.csv","TreatAsMissing","NOVALUE");
Here, 'Filename.csv' refers to the .csv file. As output, all table elements corresponding to "NOVALUE" would get set to NaN.
Hope this helps!




Community Treasure Hunt

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

Start Hunting!

Translated by