如何从元胞数组创建双打?

How to create doubles from cell arrays?

请问是否有更高效的代码来完成以下任务:

a = cell(10,1); 

for i = 1 : 10
a{i,1} = randn(200,5);
end

for j =1:5
b{j} = [a{1,1}(:,j) a{2,1}(:,j) a{3,1}(:,j) a{4,1}(:,j) a{5,1}(:,j)];
end

谢谢!

您的解决方案运行良好。这稍微更紧凑(并且更容易概括)。如果所有单元格都包含相同大小的矩阵,则可以将它们合并为一个矩阵,并且每隔 n:

选择一列
for i = 1 : 10
    a{i,1} = randn(200,5);
end

% Transform first five cells in one big matrix
c = cat(2,(a{1:5}));
n = size(a{1} , 2);

b = cell(5,1);
for j =1:5
    % Take one column every 5 (or every "n" in general)
    b{j} = c(: , 1:n:end );
end