problem with TreatasEmpty using textscan command
显示 更早的评论
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
采纳的回答
更多回答(1 个)
Walter Roberson
2011-8-30
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;
类别
在 帮助中心 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!