Matlab読み書き2 D配列(複数)


%%
%         ;    ,         ,      ;
%         c      
%  :real(a(1,1)) imag(a(1,1)) real(a(1,2)) imag(a(1,2)) .....
%%

%% write
m=10;
n=20;
i=sqrt(-1);
Q=rand(m,n)+(rand(m,n)-0.5)*i;
Qk=zeros(m,2*n);
Qk(:,1:2:end) = real(Q);
Qk(:,2:2:end) = imag(Q);
fd=fopen('Q.dat', 'wb');
fwrite(fd, transpose(Qk), 'double'); % Store by row
fclose(fd);

%% read
fd=fopen('Q.dat', 'rb');
Q1=fread(fd,'double');
fclose(fd);
v = reshape(Q1,2,[])';
Q1= v(:,1) + v(:,2)*i;
Qread=transpose(reshape(Q1,n,m));
% cmp=Q - Qread;