Problem in using Fwrite
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello
I want to rewrite or write a specific value in a file by fprintf command.
there are 2 issues that i have problems, the problems illustrate by examples:
1)for example A=123456789
i want to frprintf write A as scientific format in file, what should i do?like this 123.456789e6
2)after write this to number to file, i want to have 3 space and write another value in that line.
forexample A=123456789 and b=987654321 as below:
in special byte offset of my file i want to have: 123.456789e6 [3space] 98.7654321e7
Thank you.
0 Kommentare
Antworten (3)
Guillaume
am 26 Jul. 2017
'%e' is the flag for scientific format. The spaces, you just put them in the format string, so:
fprintf(fid, '%e %e', A, b)
Additionally, you can specify the minimum number of characters that the %e conversion should occupy and the number of decimals.
4 Kommentare
Guillaume
am 26 Jul. 2017
So, rather than telling us which function (not command) you want to use and finding out it's not actually what you need, why don't you tell us exactly what it is you are trying to do? Then we can tell you how to go about it.
mohammad ali haghnejat
am 26 Jul. 2017
Bearbeitet: Walter Roberson
am 26 Jul. 2017
Walter Roberson
am 26 Jul. 2017
The only time you can safely use fwrite() to update a file is if it is a binary file and you are updating fixed-width fields. It is not possible with fwrite() to replace '123456789' with '123.456789e6' because the number of bytes is different.
The only operating system that MATLAB has ever worked on, which had operating system support for squeezing in additional bytes in the middle of a file, was VMS -- and for technical reasons, it was not possible for MATLAB to access that facility.
What you will need to do instead is read from the input file, copy the parts before where you want to change into an output file, read the old value to be changed from the input file, write the modified version to the output file, and then resume copying from input to output.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Install Products finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!