相关疑难解决方法(0)

MATLAB中的textscan:将NULL值读为NaN

我有一个包含以下数据的.txt文件:

sampleF.txt - >(制表符分隔)

MSFT    200    100
APPL    10    NULL
AMZN    20    40
Run Code Online (Sandbox Code Playgroud)

我需要使用读取此数据textscan.我在阅读NULL数据时遇到问题.使用treatasemptyparam,我可以把它读成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)

file-io matlab nan tsv textscan

2
推荐指数
1
解决办法
2485
查看次数

标签 统计

file-io ×1

matlab ×1

nan ×1

textscan ×1

tsv ×1