我有一个包含以下数据的.txt文件:
MSFT 200 100
APPL 10 NULL
AMZN 20 40
Run Code Online (Sandbox Code Playgroud)
我需要使用读取此数据textscan
.我在阅读NULL
数据时遇到问题.使用treatasempty
param,我可以把它读成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] }
Run Code Online (Sandbox Code Playgroud)