problem with TreatasEmpty using textscan command
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 30 Août 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;
Catégories
En savoir plus sur Text Data Preparation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!