필터 지우기
필터 지우기

Fread problem...

조회 수: 19 (최근 30일)
jason beckell
jason beckell 2012년 1월 26일
Hello to everyone!
I have a problem with the following simple portion of code:
b = rand(5, 1);
fid = fopen('prova.bin', 'w');
fwrite(fid, b);
fclose(fid);
% Read the contents back into an array
fid = fopen('prova.bin');
B = fread(fid, 5, 'double');
fclose(fid);
Fread doesn't seem to work, how come ? Has any of you got an idea?
Thank you very much and my best regards! Jason.

답변 (2개)

Thomas
Thomas 2012년 1월 26일
Add type 'double' in your fwrite
b = rand(5, 1);
fid = fopen('prova.bin', 'w');
fwrite(fid, b,'double'); % add type double here
fclose(fid);
% Read the contents back into an array
fid = fopen('prova.bin');
B = fread(fid, 5, 'double');
fclose(fid);
should work

Bård Skaflestad
Bård Skaflestad 2012년 1월 26일
You need to specify the precision of the data you output using fwrite is double. Otherwise, the subsequent fread operation fail. I'd write the above as
b = rand(5, 1);
fid = fopen('prova.bin', 'w');
fwrite(fid, b, 'double');
fclose(fid);
% Read the contents back into an array
fid = fopen('prova.bin');
B = fread(fid, 5, 'double');
fclose(fid);

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by