Re: writing data to multiple files
- From: roberson@xxxxxxxxxxxxxxxxxx (Walter Roberson)
- Date: Thu, 6 Mar 2008 16:57:30 +0000 (UTC)
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
.
- References:
- writing data to multiple files
- From: Ender
- Re: writing data to multiple files
- From: Walter Roberson
- Re: writing data to multiple files
- From: Ender
- writing data to multiple files
- Prev by Date: inner matrix dimensions must agree!
- Next by Date: Re: [Error]-Using matlab function with VC++2003- please help me
- Previous by thread: Re: writing data to multiple files
- Next by thread: Matlab compiler issues
- Index(es):
Relevant Pages
|