% MatlabFileTest.m
a=10;b=20;
A=zeros(a,b);
k=0;
for j=1:b
for i=1:a
k=k+1;
A(i,j)=k;
end
end
% A(i,j), where i indicates row index, j indicates collumn index
filename = sprintf('InputFile.raw');
fid = fopen(filename,'wb');
fwrite(fid,A,'double');
fclose(fid);
% save the 2D matrix column by column, i.e. A(:,1),A(:,2),...,A(:,b)
% In matlab A(i,j)=A((i-1)*Na+j)
fid=fopen(filename,'rb');
B=fread(fid,[a,b],'double');
fclose(fid);
% read the 2D matrix column by column, i.e. A(:,1),A(:,2),...,A(:,b)
% In matlab B(i,j)=B((i-1)*Na+j)
imagesc(B);
colorbar;
%%
filename = sprintf('OutputFile2');
fid=fopen(filename,'rb');
C=fread(fid,[a,b],'double');
fclose(fid);
imagesc(C);
colorbar;
------------------------------------------------------
// C++FileTest.cpp
#include <stdlib.h>
#include <iostream>