将 3d 元胞数组转换为 2d 元胞数组

convert 3d cell array in 2d cell array

我将结构 S(有 13 个字段和 96 行,一些字段由数字组成,其他字段由字符串组成)转换为元胞数组:

myCell= struct2cell(S);

因此,我获得了一个 3d 元胞数组 myCell 13x1x96,我想将其转换为 2d 元胞数组 96x13。欢迎任何建议!

比所建议的更通用的解决方案将使用 permute 函数:

B = permute(A,order) rearranges the dimensions of A so that they are in the order specified by the vector order.

...

permute and ipermute are a generalization of transpose (.') for multidimensional arrays.

在您的情况下,运行 命令 new_Cell = permute(myCell,[3,1,2]) 将使 13x1x96 96x13。如您所见,permute 删除了尾随的单例维度(类似于 squeeze)。

(在 MATLAB 2015b 上测试)