필터 지우기
필터 지우기

fwrite

조회 수: 5 (최근 30일)
Tor Fredrik Hove
Tor Fredrik Hove 2011년 11월 18일
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

채택된 답변

Titus Edelhofer
Titus Edelhofer 2011년 11월 18일
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
Tor Fredrik Hove
Tor Fredrik Hove 2011년 11월 18일
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 2011년 11월 18일
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)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by