|
Prev: Page break
Next: Convert Excel Array to Matlab Matrix
From: Alex on 18 Jun 2008 10:14 us: Thanks for the response. I checked and this way definitely works, but a problem I'm having is that I'm printing anywhere from 10 to 100 million of these numbers tab delimited in a word file... i was kinda hoping for an easier way to do it. I mean i could always build the number as a string then just cut out the zeros after the E, but a process like that would slow down the program too much to make it worth it.
From: dpb on 18 Jun 2008 14:46 Alex wrote: > us: > > Thanks for the response. I checked and this way definitely works, > but a problem I'm having is that I'm printing anywhere from 10 to 100 > million of these numbers tab delimited in a word file... i was kinda > hoping for an easier way to do it. > > I mean i could always build the number as a string then just cut out > the zeros after the E, but a process like that would slow down the > program too much to make it worth it. For some reason us' response wasn't (or at least hasn't yet) on my news server so don't know what he suggested specifically. I gather it was similar at least to mine... As for the latter, you could try just writing the file as is and then post process it in large chunks as char array and do a global substitution for the E+/-00 substring. That _might_ be fast enough although it would seem there are few compelling reasons that it would have to be done. --
From: Walter Roberson on 18 Jun 2008 14:49 In article <18811602.1213812880599.JavaMail.jakarta(a)nitrogen.mathforum.org>, Alex <buchholz.alex(a)orbital.com> wrote: >Thanks for the response. I checked and this way definitely works, but a problem I'm having is that I'm printing anywhere from 10 to 100 million of these numbers tab delimited in a word file... i was kinda hoping for an easier way to do it. >I mean i could always build the number as a string then just cut out the zeros after the E, but a process like that would slow down the program too much to make it worth it. There is no matlab supplied way of doing this except through string manipulation. The C89 standard for the C fprintf() library call says that the number of digits in the exponent will be at least two. -- "Every intellectual product must be judged from the point of view of the age and the people in which it was produced." -- Walter Horatio Pater
From: us on 18 Jun 2008 15:35 Alex: <SNIP pre-processing large chunks of data... > I checked and this way definitely works, but a problem I'm having is that I'm printing anywhere from 10 to 100 million of these numbers tab delimited in a word file... well, let's see how the snipplet below works on a wintel system: ic2.2*2.4mhz/2gb/winxp.sp4/r2008a/bad hd Elapsed time is 21.635499 seconds. % for: ans = 153101529 % file size of: % 1000010 x 10 = 10000100 processed numbers % now - if it comes to 10 times as much... us % the data x=23456789; nr=1000010; nc=10; m=reshape(1:nr*nc,nr,nc); fnam='zoo.txt'; % the engine fmt=[repmat('%15.5G ',[1,size(m,2)]),... sprintf('\\t\\n')]; % - write blocks of min size 100000 [mr,mc]=size(m); bs=min(mr,100000); bn=fix(mr/bs); be=mr-bn*bs; bx=1:bs; % - open the file [fp,msg]=fopen(fnam,'wt'); if fp < 0 disp(msg); return; end % - write bn blocks tic for i=1:bn cx=(i-1)*bs+bx; sm=strrep(sprintf(fmt,m(cx,:).'),'E+0','E+'); fwrite(fp,sm,'uchar'); end % - write be leftovers if be cx=i*bs+bx(1:be); sm=strrep(sprintf(fmt,m(cx,:).'),'E+0','E+'); fwrite(fp,sm,'uchar'); end toc % close the file fclose(fp); % the result f=dir(fnam); f.bytes
From: dpb on 18 Jun 2008 17:13 Walter Roberson wrote: .... > There is no matlab supplied way of doing this except through string > manipulation. The C89 standard for the C fprintf() library call says > that the number of digits in the exponent will be at least two. I had one other idea (but it didn't work, either) which was to try to output the values as single(x) but the single class is underprivileged and has no i/o functions implemented. I wasn't sure whether there was a way in Standard C to specify the exponent width or not. Fortran has the form Ew.d[Ee] "The exponent field width (e) is optional for the E edit descriptor; if omitted, the default value is 2. If e is specified, the w should be greater than or equal to d+e+5." So I thought perhaps C had caught up, maybe... :) --
|
Pages: 1 Prev: Page break Next: Convert Excel Array to Matlab Matrix |