Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 如何从.dat文件中获取一组2d矩阵,并将它们放入一个大的3d矩阵中?_Matlab_Matrix - Fatal编程技术网

Matlab 如何从.dat文件中获取一组2d矩阵,并将它们放入一个大的3d矩阵中?

Matlab 如何从.dat文件中获取一组2d矩阵,并将它们放入一个大的3d矩阵中?,matlab,matrix,Matlab,Matrix,我正在尝试将.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'

我正在尝试将.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
最后,我想通过使用
norm((在此处插入3d矩阵),2)

我遇到的问题是,我不知道如何将我刚刚制作的所有矩阵组合成一个大的3D矩阵

解决方案

使用

或使用

T=cat(3,B{:})
持续问题

这现在不起作用:

norm(T,2) //Should compute the L2 norm of my 3D matrix, right?
但这可能超出了这个问题的范围

据我所知,我认为必须在二维矩阵上使用norm。

一旦有了B,运行:

matrix3d = zeros(41,21,40);
for i=1:40
    matrix3d(:, :, i)=B{i};
end
您还可以包括
matrix3d(:,:,i)=B{i}并调用
matrix3d=zero(41,21,40)在进入循环之前

一旦有了B,运行:

matrix3d = zeros(41,21,40);
for i=1:40
    matrix3d(:, :, i)=B{i};
end
您还可以包括
matrix3d(:,:,i)=B{i}并调用
matrix3d=zero(41,21,40)在进入循环之前

答案就在这里

T=Cat(3,B{:}) //Combines all matrices into one single 3D matrix
答案是这样的

T=Cat(3,B{:}) //Combines all matrices into one single 3D matrix

哦,太好了!但是直接在循环中填充3D可能更合适,而不必创建临时变量B。哦,太好了!但是直接在循环中填充3D可能更合适,而不必创建临时变量B。对不起,我没有答案,需要马上去开会。对不起,我没有答案,需要马上去开会。