我正在尝试将 .dat 文件中的所有这些 2d 矩阵组合成一个 3d 矩阵。
所以到目前为止我所做的是:
for (i=1:40) //There are 40 of these files
fileName = ['Solutionm1.dat/Solution' num2str(i-1) '.dat'] //This line sets a file name
f=fopen(fileName,'r') //I'm just opening the file now
A{i}=fread(f,'double') //Now I'm converting the binary file into a matlab matrix
B{i}=reshape(A{i},41,21) //Now I'm putting it into the shape that I want (I don't know of a better way to read binary files)
fclose all
end
最终,我想通过使用这个 3d 矩阵的 L2 范数norm((insert 3d matrix here),2)
我遇到的问题是我只是不知道如何将我刚刚制作的所有矩阵组合成一个大的 3D 矩阵。
解决方案
利用
T(:,:,i)=B{i}
或使用
T=cat(3,B{:})
持续的问题
这现在不起作用:
norm(T,2) //Should compute the L2 norm of my 3D matrix, right?
虽然这可能超出了这个问题的范围......
根据我所学到的,我认为 norm 必须用于 2D 矩阵。