连接单元格数组

Mik*_*ith 4 arrays matlab cell

我希望将两个单元阵列连接在一起.我有两个不同大小的矩阵,根据我的理解,将它们连接在一起的唯一可能方法是使用单元格数组.这是我的代码

M = magic(3);
B = {magic(3) 'sip' magic(4) magic(3) }

C = {B; ...
        B; ...
        B; ...
        B}


c1 = C{1}{1,1};
c2 = C{1}{1,3};
c{1} = c1; % after extracting matrix from cell array put it it
c{2} = c2; % into another cell array to attempt to concatenate
conca = [c{1};c{2}]; %returns error.
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

??? Error using ==> vertcat
CAT arguments dimensions are not
consistent.

Error in ==> importdata at 26
conca = [c{1};c{2}]; %returns error.
Run Code Online (Sandbox Code Playgroud)

Heb*_*odo 5

我认为这是你想要的输出:

conca = 

    [3x3 double]
    [4x4 double]
Run Code Online (Sandbox Code Playgroud)

在哪里conca{1}:

 8     1     6
 3     5     7
 4     9     2
Run Code Online (Sandbox Code Playgroud)

conca{2}是:

16     2     3    13
 5    11    10     8
 9     7     6    12
 4    14    15     1
Run Code Online (Sandbox Code Playgroud)

你实际上非常接近.您需要的只是将方括号更改为花括号.像这样:

conca = {c{1};c{2}};
Run Code Online (Sandbox Code Playgroud)

我实际上不明白你为什么使用C而不仅仅是

conca = {B{1};B{3}}
Run Code Online (Sandbox Code Playgroud)

那会给你相同的单元格数组.