problem with TreatasEmpty using textscan command
Show older comments
I am having issues reading a data file. The particular line of code that I am having problems with involves treatasempty and textscan.
Below is the data line that I am having issues with:
STM SPEED (KT) 10 12 12 12 12 12 N/A N/A N/A N/A N/A N/A N/A
Right now, I navigate to grab the necessary information from this line with the command
stormspeed = textscan(fid, '%s' , 12. 'HeaderLines',13, 'treatAsEmpty',{'N/A'});
The problem is stormspeed does not correspond to what I want. For example, stormspeed{1}=
'STM'
'SPEED'
'(KT)'
'10'
'12'
'12'
'12'
'12'
'12'
'N/A'
'N/A'
'N/A'
But I want the N/A to be replaced with NaN. Is this possible?
thanks, Kieran
Accepted Answer
More Answers (1)
Walter Roberson
on 30 Aug 2011
No, not when you are using %s . The TreatAsEmpty documentation says specifically that it only applies to numeric fields.
You can use
stormspeed{1}(ismember('N/A', stormspeed{1})) = nan;
Categories
Find more on Text Data Preparation 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!