[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
reading file
From: |
marco cammarata |
Subject: |
reading file |
Date: |
Mon, 25 Feb 2008 18:36:43 +0100 |
Hi,
I would like to read a file that looks like this
a b c
1 2 3
4 5 6
in a structure where data.a contains the first columns (e.g. 1 and 4 in
2 rows), data.b the second and so on.
I wrote something that seems to work:
file = "file_to_read.txt";
F=fopen(file,"r");
titles=fgetl(F);
titles=regexprep(titles,'\s+',' ');
titles=split(titles," ");
fields=cellstr(fields);
nfile=0;
while ( (line=fgetl(F)) != -1 )
if (line == -1)
break
endif
nfile = nfile+1;
temp=regexprep(line,'\s+',' ');
temp=split(temp," ");
temp=cellstr(temp);
for i=1:size(fields)
cmd=sprintf("data(%d).%s=\"%s\";",nfile,fields(i),temp(i));
% disp(cmd)
eval(cmd);
endfor
endwhile
close(F);
but it's a bit too slow ... for a 19 columns and 130 rows it takes
almost 2 seconds !!! (on a xeon machine).
Any suggestion ?
Another question,
How can I plot let's say "data.a" ?
Octave complains saying that has noting to plot ...
Many thanks in advance,
attached please find the octave script and a sample file ..
marco
--
Marco Cammarata,
Post-Doc
European Synchrotron Radiation Facility
Material Science Group
6, rue Jules Horowitz
BP 220, Grenoble Cedex 38043, FRANCE
Beamline ID09b
Office : +33 (0)4 76 88 29 37
Beamline : +33 (0)4 76 88 26 95
Fax : +33 (0)4 76 88 27 43
email: address@hidden
http://www.esrf.fr/UsersAndScience/Experiments/MaterialsScience/ID09B/
http://www.fisica.unipa.it/~emoglobina/marco
~
file_to_read.txt
Description: Text document
test.octave
Description: Text document