use fprintf to write to a new file
Show older comments
How do I write the data of one file ('source.dat') to another ('result.dat') using fprintf?
I tried,
fid=fopen('source.dat')
%I then manipulate the data of fid to my liking
result=fopen('result.dat','w')
fprinf(fid, desired format here)
Why am I getting an out-of-range error?
1 Comment
dpb
on 24 Jul 2013
Need the actual code and the error directly instead of trying to tell us what it was...that'll include --- oh, I see it if what you actually did is identically what you posted...see answers.
Accepted Answer
More Answers (1)
dpb
on 24 Jul 2013
fid=fopen('source.dat')
% do some stuff to the (presumed read but unshown) data from 'source.dat'
result=fopen('result.dat','w')
fprinf(fid, desired format here)
fid is still the handle for 'source.dat' or is invalid if you have done an
fclose(fid)
OTOMH I don't recall what that error message is, would think it would be invalid handle or somesuch, however, not some out-of-range error.
The handle to 'result.dat' is the variable result as you've written it above so the print statement (Fortran syntax :) )/fprintf call should be
fprintf(result, fmt, data)
NB: there's no data in the call above to be written.
But, while those are problems, w/o the actual code and specific error can't see w/ the cloudy crystal ball what actually was the cause of the specific error or what it means.
1 Comment
ERC
on 24 Jul 2013
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!