freadcomplex and fwritecomplex

Mex routines that read and write interleaved complex data files for MATLAB R2018a or later without extra data copy.

現在この提出コンテンツをフォロー中です。

freadcomplex and fwritecomplex are mex routines that read and write an interleaved complex data file for R2018a or later. It first reads the file as real with twice the first dimension using the MATLAB fread function, then internally converts this variable into an interleaved complex variable with the original requested size. The internal conversion from real to complex is a straight conversion without any extra data copy. For writing, it creates a temporary pseudo shared data real variable and then calls the MATLAB fwrite function. That is, no extra data copies are involved in the reading and writing.

Since these mex routines use the MATLAB fread and fwrite functions, the syntax is the same as these functions:

A = freadcomplex(fileID)
A = freadcomplex(fileID,sizeA)
A = freadcomplex(fileID,sizeA,precision)
A = freadcomplex(fileID,sizeA,precision,skip)
A = freadcomplex(fileID,sizeA,precision,skip,machinefmt)
[A,count] = freadcomplex(___)

fwritecomplex(fileID,A)
fwritecomplex(fileID,A,precision)
fwritecomplex(fileID,A,precision,skip)
fwritecomplex(fileID,A,precision,skip,machinefmt)
count = fwritecomplex(___)

E.g.,
>> x = reshape(1:16,4,4)
x =
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
>> fid = fopen('test.dat','wb');
>> fwrite(fid,x,'double');
>> fclose(fid);
>> fid = fopen('test.dat','rb');
>> freadcomplex(fid,'*double') % read as column
ans =
1.0000 + 2.0000i
3.0000 + 4.0000i
5.0000 + 6.0000i
7.0000 + 8.0000i
9.0000 +10.0000i
11.0000 +12.0000i
13.0000 +14.0000i
15.0000 +16.0000i
>> frewind(fid);
>> freadcomplex(fid,[2 4],'*double') % read as halve first dimension
ans =
1.0000 + 2.0000i 5.0000 + 6.0000i 9.0000 +10.0000i 13.0000 +14.0000i
3.0000 + 4.0000i 7.0000 + 8.0000i 11.0000 +12.0000i 15.0000 +16.0000i
>> frewind(fid);
>> freadcomplex(fid,[4 2],'*double') % read as halve second dimension
ans =
1.0000 + 2.0000i 9.0000 +10.0000i
3.0000 + 4.0000i 11.0000 +12.0000i
5.0000 + 6.0000i 13.0000 +14.0000i
7.0000 + 8.0000i 15.0000 +16.0000i
>> fclose(fid);

引用

James Tursa (2026). freadcomplex and fwritecomplex (https://jp.mathworks.com/matlabcentral/fileexchange/77530-freadcomplex-and-fwritecomplex), MATLAB Central File Exchange. に取得済み.

一般的な情報

MATLAB リリースの互換性

  • R2018a 以降のリリースと互換性あり

プラットフォームの互換性

  • Windows
  • macOS
  • Linux
バージョン 公開済み リリース ノート Action
1.1.0

Updated freadcomplex for handling of inf sizes. Added new fwritecomplex routine.

1.0.0