[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to efficiently write formatted file output ...

From: Przemek Klosowski
Subject: Re: How to efficiently write formatted file output ...
Date: Fri, 17 Jun 2016 15:28:03 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1

On 06/17/2016 02:51 PM, Dr.-Ing. Dieter Jurzitza wrote:
 for i=1:100000
    fprintf(outfile, "%d %12.10f %12.10f %12.10f\n", j(i), s(i), B(i), A(i));
The elapsed time is said to be 4.2 seconds. 
 fprintf(outfile, "%d %12.10f %12.10f %12.10f\n", j, s, B, A);
doesn't do the right thing, as the arrays are treated one after the other, 
leading to a strange looking output file, however the elapsed time goes down 
to 0.38s or 1/10th of the time used for the "for" loop.
Right, because interpreted loops are slow. The best way to speedup is to avoid loops, which is always desirable in Octave, because it leads to code that's usually faster, shorter AND better and thus easier to read.

 All data I want to write to the file are in there, but you know, the order of the data is not 
what I hoped it to be.
Right, so you need to rearrange the data so that it's in the proper order:

fprintf(outfile,"%d %12.10f %12.10f %12.10f\n", [j;s;B;A])

reply via email to

[Prev in Thread] Current Thread [Next in Thread]