我有一个包含以下数据的 .txt 文件:
sampleF.txt -->(制表符分隔)
MSFT 200 100
APPL 10 NULL
AMZN 20 40
我需要使用textscan
. 我在读取NULL
数据时遇到问题。使用treatasempty
参数,我可以将其读为 0。但我想将其读为NaN
. 请帮忙!谢谢!
fName = '.....\sampleF.txt'
[fid, message] = fopen(fName) ;
if fid < 0, disp(message), else
datatxt = textscan(fid, '%q %d %d', 'Delimiter', '\t','treatAsEmpty','NULL');
datatxt = [ datatxt {1} num2cell(datatxt {2}) num2cell(datatxt {3})] ;
fclose(fid) ;
end
%datatxt = { 'MSFT' [200] [100] ; 'AAPL' [10] [NaN] ; 'AMZN' [20] [40] }