Write/read binary files

14 visualizaciones (últimos 30 días)
Hoan Nguyen
Hoan Nguyen el 31 de Mzo. de 2020
Respondida: per isakson el 31 de Mzo. de 2020
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)

Respuestas (1)

per isakson
per isakson el 31 de Mzo. de 2020
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

Categorías

Más información sobre Data Import and Analysis 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