Write/read binary files

조회 수: 15 (최근 30일)
Hoan Nguyen
Hoan Nguyen 2020년 3월 31일
답변: per isakson 2020년 3월 31일
Hi,
Not sure where the bugs are or what I did wrong. I saved arrays of complex numbers in a Matlab binary file and then read out the numbers from the saved file. The values don't match. Saved values are e^-6 and read-out values are e^389. Codes are below.
%write codes
fido = fopen(filename_out,'w','ieee-be');
tmpdatR(:,:) = real((X));
tmpdatI(:,:) = imag((X));
tmpdat = [tmpdatR,tmpdatI];
e=fwrite(fido,tmpdat,'double'); %fwrite is in a loop
fclose(fido)
%read codes
fido=fopen(filename,'r','ieee-be');
XCtemp=fread(fido,inf,'double');
fclose(fido)

답변 (1개)

per isakson
per isakson 2020년 3월 31일
This script
%%
ffs = 'test.bin';
X = 1+2i;
%% write codes
fid = fopen(ffs,'w','ieee-be');
tmpdatR = real((X));
tmpdatI = imag((X));
tmpdat = [tmpdatR,tmpdatI];
e=fwrite(fid,tmpdat,'double'); %fwrite is in a loop
fclose(fid);
%% read codes
fid=fopen(ffs,'r','ieee-be');
XCtemp=fread(fid,inf,'double');
fclose(fid);
%%
tmpdat, XCtemp
outputs
tmpdat =
1 2
XCtemp =
1
2
I'm not sure what's going wrong with your code

카테고리

Help CenterFile Exchange에서 Adding custom doc에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by