Write/read binary files
11 ビュー (過去 30 日間)
古いコメントを表示
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)
0 件のコメント
回答 (1 件)
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!