Writing a integer in an existing file
Afficher commentaires plus anciens
Hello,
I'm trying to overwrite a file with a int16 precission value and I'm not able to do it. I'm usign this code ('x.DBL' is the name of the file):
fp=fopen('x.DBL','r+');
fwrite(fp,dd,'int16'); %dd is a variable with 73 elements
The ans to that command is 0, so I'm realizing that it is not overwriting anything.
Before that, I've read dd by using dd=fread(fp,73,'int16'); and it works perfectly.
Can someone help me please? Thanks in advanced,
RRR
4 commentaires
Ameer Hamza
le 3 Nov 2020
This command is working fine on my system. Have you checked the content of the file using hexdump?
Roselena Rubino
le 3 Nov 2020
Ameer Hamza
le 3 Nov 2020
Can you paste your code here exactly.
Roselena Rubino
le 3 Nov 2020
Réponses (1)
Walter Roberson
le 3 Nov 2020
0 votes
You must fseek every time you switch between reading and writing. Telling fseek to move 0 bytes cof is fine for this purpose.
1 commentaire
Roselena Rubino
le 11 Nov 2020
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!