% 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>
using namespace std;
int main(void) {
int Na=10; // height of the detector

本文提供了一组测试代码,演示了Matlab和C如何动态开辟内存、处理矩阵数据,并进行文件读取交互。在Matlab中创建矩阵,然后在C++程序中读取并处理这些数据。
最低0.47元/天 解锁文章
3551

被折叠的 条评论
为什么被折叠?



