usage of textscan in Octave 3.8.2

192 views Asked by At

The following is working fine when reading a data file of "1.2D+02 3.23D+01 ...." in matlab;

tempvs = textscan ( input_unit, '%f', N );
tempvs = cell2mat(tempvs);
tempvs = double(tempvs); 

But, the same would not work (does not recognize "D" numbers) in octave (ver. 3.8.2) so i modified a little like the following;

tempvs = textscan ( input_unit, '%s', N );
tempvs = cell2mat(tempvs);
values = zeros(N,1);
for i = 1: N
   values(i) = str2num(tempvs{i,1});
end

Is there other efficient way to do the job? Thanks in advance for youe help.

NOTE: changing data file into "1.2E+02 3.23E+01 ...." form is not an option, already tried line-by-line reading using fgetl but its slow.

1

There are 1 answers

0
Markus On

fopen the file, read all at once fread(fid, "char=>char").' and try textscan ( regexprep(input_unit,"D","E"), '%f' ) when your file looks like input_unit="1.2D+02 3.23D+01" everywhere. This should be blazing fast as long as your file fits into your RAM. But I dunno what D numbers are?