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])
|