用matlab生成一个矩阵,怎样正确的保存到本地的硬盘然后在VC中正确的读入这个矩阵?

来源:百度知道 编辑:UC知道 时间:2024/06/07 01:35:51
我用一段Matlab程序获得一个矩阵12*526,
这个矩阵将用到一个C程序中。
我怎样将这个矩阵正确的保存到硬盘中 然后导入到C程序里?

matlab中使用fwrite。
fwrite(fid,magic(5),'integer*4')
creates a 100-byte binary file containing the 25 elements of the 5-by-5 magic square, stored as 4-byte integers.
c中使用fopen,读取到二维数组中
int num_read = fread(buf, 1, length, fp);

最安全的办法,用matlab的fprintf语句输出到文本文件,再用C的fscanf语句读入。

如果你的矩阵是C,可以用下面的语句把它写成a.txt文档放入盘
dlmwrite('a.txt',C)