fwrite

5 visualizaciones (últimos 30 días)
Tor Fredrik Hove
Tor Fredrik Hove el 18 de Nov. de 2011
I tried to use fwrite which is described as saving in binary form but it saved it in numbers. At least my attempt did:
Created a new file rain2.tv and atached too numbers to it and read it afterwards:
>> fid=fopen('rain2.tv','w')
fid =
3
>> fwrite(fid, '2 4')
ans =
3
When i open the file rain2.tv it is in normal numbers not binary and when I look at the saved file it is also saved in normal

Respuesta aceptada

Titus Edelhofer
Titus Edelhofer el 18 de Nov. de 2011
Hi Tor,
1) you save strings 2,4, not values (pass [2 4] instead of '2 4' to fwrite
2) you should pass the format ('double'), see fwrite doc
Titus
  2 comentarios
Tor Fredrik Hove
Tor Fredrik Hove el 18 de Nov. de 2011
I have read doc fwrite but I can't seem t oget a specific example. I have written:
>> fid=fopen('rain2.tv','w')
fid =
3
>> fwrite(fid, [1 2])
ans =
2
>> fclose(fid)
ans =
0
>> fopen('rain2.tv')
ans =
3
>> while ~feof(fid)
fgetl(fid)
end
ans =
>>
the ans is empty and noting is saved in the file
Walter Roberson
Walter Roberson el 18 de Nov. de 2011
The ans is not empty: I can see from what you posted that it contains two characters, binary 1 and binary 2.
fgetl() is used for reading *text*, not for reading binary. You would use fread() to read binary.
fread(fid)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Low-Level File I/O en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by