Re: writing data to multiple files



In article <fqovpu$dmc$1@xxxxxxxxxxxxxxxxxx>, Ender <jr147@xxxxxxxxxxx> wrote:

I changed the code from a previous version. I want to
write to multiple files. Meaning that once I write to file
(A_1), When the iteration starts over, I want to write the
next dataset to A_2 until I get to A_nsteps. This is the
code that I am trying to use, but it keeps writing over
the file instead of creating then writing to a new file:

for K=1:1
filename = sprintf('time_step_%d.doc', K);

This code does not write to A_* at all; it writes to
time_step_1.doc . (Note: you would not usually want
to create a .doc file yourself, as Windows would think that
it was an MS Word file.)


fid = fopen(filename,'w');
fprintf(fid,' time(sec)=%4.16f\n',elements(1));
fprintf(fid,' Semi-major axis(km)=%4.16f\n',elements(2));
fprintf(fid,' Eccentricity =%4.16f\n',elements(3));
fprintf(fid,' inclination angle (deg)=%4.16f\n',elements
(4));
fprintf(fid,' Right Ascension of the ascending node (deg)=%
4.16f\n',elements(5));
fprintf(fid,' Argument of Periapsis (deg)=%
4.16f\n',elements(6));
fprintf(fid,' True anomaly (deg)=%4.16f\n',elements(7));
fclose(fid);
end

The only problem I see there is that you have K=1:1 which
is the same as just doing the loop once with K=1. Instead of
using a loop over K here, put these as statements directly in
your loop over your timesteps, and replace the K in the sprintf
with the name of your timestep variable.
--
"Man's life is but a jest,
A dream, a shadow, bubble, air, a vapor at the best."
-- George Walter Thornbury
.



Relevant Pages

  • Re: what does "serialization" mean?
    ... >> resource reasons). ... >> other forms of writing saying what you really mean to say is a writing ... If you consider all loop forms of all languages, ... exposed "iteration" API. ...
    (comp.programming)
  • Re: for loop without variable
    ... iteration I'm on isn't important to me. ... attempt the web services that number of times. ... function which has the loop in it) returns True. ... you've hidden that meaning by giving it the meaningless name "i". ...
    (comp.lang.python)
  • Most efficiant use of stringbuilder
    ... (these are generated inside a datareader loop) ... #2 Append the data into stringbuilder variable, ... #3 Append the data into stringbuilder variable, writing to the file ... iteration ...
    (microsoft.public.dotnet.languages.vb)
  • Re: next step in for loop.....help me
    ... You can increment it just by writing a new value to the variable, but as soon as the next iteration of the loop starts, the variable will be reset to what would have been the next in progression if you had not changed it. ...
    (comp.soft-sys.matlab)
  • Re: prel doubt
    ... > SIva Rajesh ... ended and the next iteration of the loop begins. ...
    (comp.lang.perl.misc)