Convert <undefined> to NaN or leave blank
Show older comments
When reading in a table, columns with blank cells are read in as type "cell". I need to convert those columns to numeric, with blank cells being NaN or left empty. In previous version of Matlab, I could convert them to "categorical", but with the Matlab update to 2022b, the blank cells are listed as <undefined> after conversion. How can I change these undefined values to NaN or leave them empty, or just change the black cell values to NaN?. I've listed my current code and have attached a sample of the data. Im particularly concerned about Var60:Var80. The top image is what the data looks like prior to converting to categorical. The second image is what it looks like after converting it to categorical.


Mo=readtable('MW_samples_Mathworks.csv');
Mo(1:3,:)=[];
Mo = removevars(Mo,{'Stevens','DATASETCOMPLETE','endTime','USGS','Nozzle','Transits','Tagline','Water','Sample'...
'Sampling','Pump','Pump_1','Cross_section','Var30','Laboratory_determinedValues','Var32','Var33','Var34','Var35'...
'Var36','Var37','Var38','Var39','Var40','Var41','Var42','Var43','Var44','Var45','Var46','Var47','Var48','Var49','Var50','Var51'...
'Var52','Var53','Var54','Var55','Var56','Var57','Var58','ColorOf','SpecificConductance','TDS','AirTemp','WaterTemp',...
'Concentration','Grain_size','LabNotes','MethodUsedForDetermining','x95__confidence_level','x95__confidence_level_1',...
'x95__confidence_level_2','x95__confidence_level_3','x95__confidence_level_4','x95__confidence_level_5','x95__confidence_level_6'...
'x95__confidence_level_7','x95__confidence_level_8','x95__confidence_level_9','Var101','Var102','CorrectionForNegative'});
Mo = convertvars(Mo,@iscellstr,'categorical');
Accepted Answer
More Answers (0)
Categories
Find more on Lengths and Angles 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!