I have a .txt file with the following data:
sampleF.txt --> (tab delimited)
MSFT 200 100
APPL 10 NULL
AMZN 20 40
I need to read this data using textscan
. I am facing a problem while reading the NULL
data. Using treatasempty
param, I can read it as 0. But I want to read it as NaN
. Please help! Thanks!
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] }