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!