Matlab MemMapFile用于三维矩阵

时间:2014-12-11 02:25:07

标签: arrays matlab memory matrix hibernate-mapping

我有一个名为" Shanto"的三维矩阵。大小(232,232,3052)。

我想对内存进行映射,并使用以下命令:

fileID = fopen('Shanto.dat','w');

fwrite(fileID, Shanto, 'single');

fclose(fileID) 

m = memmapfile('Shanto.dat')

然而,当我尝试访问m.Data时,我得到一个657083392 x 1 uint8数组。

如何使其保留原始矩阵的(232,232,3052)形状?

谢谢,

1 个答案:

答案 0 :(得分:1)

加载.dat文件时,您可以指定形状/格式(实际默认为uint8)。 您还需要使用fwrite指定正确的数据格式:

fileID = fopen('Shanto.dat','w');

fwrite(fileID, Shanto, 'uint8'); %// Instead of 'single' as before.

fclose(fileID) 

m = memmapfile('Shanto.dat','Format',{'uint8',[232 232 3052],'MyFancyName'})

然后,您可以使用m.Data.MyFancyName

访问相应的3D阵列

更多信息here