2016-08-18 109 views
1

细胞的我写在哪里存储3点矩阵(abc)的小区(D)的内部的简单的matlab测试代码。然后我创建了一个索引向量(idx),所以我只能选择出第一个和第三个矩阵。该代码介绍如下:串联矩阵出在Matlab

% Begin code % 
a = [0 1; 2 3];  % matrix a 
b = [4 5];    % matrix b 
c = [5 6; 7 8; 9 10]; % matrix c 

D = cell(3,1);   % Initialize cell D 
D{1,1} = a; D{2,1} = b; D{3,1} = c; % Copy matrices inside cell 

idx = [1 3]'; % Indexes vector 

D = D(idx); % select matrix a and c from D 
% End code (Solution should start from here...) % 

如果我显示D{:,1}我所得到的是

ans = 

    0  1 
    2  3 

ans = 

    5  6 
    7  8 
    9 10 

我的目标是连接2点矩阵(A,B)从细胞d的一聪明的方式(使用一些特定的内置matlab函数),并可能避免for循环; 这就是我想要的东西:

E = [0 1 
    2 3 
    5 6 
    7 8 
    9 10]; 

的解决方案应该是最优雅的可能,但我愿意接受任何建议。唯一的约束应该不是改变我提出的代码,因为解决方案应该是我写的内容的延续。

注意:因为我所要做的应该矩阵的不确定数量的工作(在这个例子中,我只有3个,但可能是还1000),像E = [D{1,:};D{2,1}]解决方案是不能接受的。

回答

2

回答我的问题找到here

cat(1,D{:}) 
+0

Puoi anche usare'vertcat(d {:})':-) –