Prev: canoncorr
Next: setmcruserdata
From: marco sala on 12 Oct 2009 08:29 Hi I have a little problem. For my degree thesis I have to read a file which contains floating numbers. The size is huge (like ~1 GB) so Matlab can't read in a variable all of the number my file it's like this -9 -8 -7 -6 ********************* 1.00000020 2.00000000 3.00000000 4.00000000 ********************* 5.00000000 6.00000000 7.00000000 8.00000000 ********************* 0.00000000 0.00000200 0.00000020 0.00000020 ********************* 0.00000000 0.00000200 0.00000020 0.00000020 ********************* 0.00000000 0.00000200 0.00000020 0.00000020 ********************* 9.00000000 10.00000000 11.00000000 12.00000000 ********************* I have 4 elements then ****** then 4 elements ect... There is a command that can read the first 4 elements then position in the other 4 and go on like this? I try fscanf textread but no one work! thanks
From: dpb on 12 Oct 2009 09:27 marco sala wrote: .... > my file i[t']s like this > > -9 > -8 > -7 > -6 > ********************* > 1.00000020 > 2.00000000 > 3.00000000 > 4.00000000 > ********************* > 5.00000000 > 6.00000000 .... > > I have 4 elements then ****** then 4 elements ect... > > There is a command that can read the first 4 elements then position > in the other 4 and go on like this? > > I try fscanf textread but no one work! .... try textscan instead--it's 'commentstyle' parameter allows to specify a comment character (and why they didn't upgrade textread at the same time is beyond me... :( )... --
From: Sebastiaan on 12 Oct 2009 09:50 I find it hard to beleive that you cannot store the contents of a 1GB text-file in your memory if you do it properly. This is a very simple, but robuust program that reads all the numbers of a file, and ignores all non-numbers (and assumes in this case that you have a multiple of 4 amount of numbers): fid = fopen('testfile.txt','r'); % Reserve memory A = zeros(100,1); Index = 0; tline = fgetl(fid); while ischar(tline) number = str2double(tline); if ~isnan(number) Index = Index + 1; A(Index) = strread(tline, '%f'); end tline = fgetl(fid); end fclose(fid); A = A(1:Index); A = reshape(A, 4, Index/4); disp(A) If it is slow, increase the allocation for A. Sebastiaan
From: Steven Lord on 12 Oct 2009 09:52 "dpb" <none(a)non.net> wrote in message news:havb3r$fcj$1(a)news.eternal-september.org... > marco sala wrote: > ... >> my file i[t']s like this >> >> -9 >> -8 >> -7 >> -6 >> ********************* 1.00000020 2.00000000 3.00000000 4.00000000 >> ********************* 5.00000000 6.00000000 > ... >> >> I have 4 elements then ****** then 4 elements ect... >> >> There is a command that can read the first 4 elements then position >> in the other 4 and go on like this? >> >> I try fscanf textread but no one work! > ... > > try textscan instead--it's 'commentstyle' parameter allows to specify a > comment character (and why they didn't upgrade textread at the same time > is beyond me... :( )... The first note on the reference page for TEXTREAD may explain it: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/textread.html "textread is not recommended. Use textscan to read data from a text file." -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: dpb on 12 Oct 2009 10:01
Steven Lord wrote: > "dpb" <none(a)non.net> wrote in message .... >> comment character (and why they didn't upgrade textread at the same time >> is beyond me... :( )... > > The first note on the reference page for TEXTREAD may explain it: > > http://www.mathworks.com/access/helpdesk/help/techdoc/ref/textread.html > > "textread is not recommended. Use textscan to read data from a text file." >> textscan ??? Undefined function or variable 'textscan'. >> may explain _my_ frustration... :( -- |