在Matlab中循环保存二进制文件



考虑Matlab中维度为mxn的矩阵A,假设我想使用

将其保存为二进制文件test.dat
File_id = fopen('test.dat', 'w');
fwrite(File_id, A, 'float32');
fclose(File_id);

现在假设A是在h=1:100的循环中创建的:我如何为二进制文件分配名称test1.dat, test2.dat,...,test100.dat ?换句话说,这就是我想要做的,我的问题与步骤2有关:

%for h=1:H
    %1)do something that creates A
    %2) Save A using
    %File_id = fopen('test'h'.dat', 'w'); %clearly wrong
    %fwrite(File_id, A, 'float32'); 
    %fclose(File_id);
%end

在您发布的代码中,行:

%File_id = fopen('test'h'.dat', 'w'); %clearly wrong

应该读:

File_id = fopen(strcat('test',num2str(h),'.dat'),'w');

,这应该可以很好地完成。

最新更新