arrays - 串联元胞数组

标签 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.

我收到以下错误:

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

Error in ==> importdata at 26
conca = [c{1};c{2}]; %returns error.

最佳答案

我假设这是你想要的输出:

conca = 

    [3x3 double]
    [4x4 double]

conca{1} 是:

 8     1     6
 3     5     7
 4     9     2

conca{2} 是:

16     2     3    13
 5    11    10     8
 9     7     6    12
 4    14    15     1

你们其实很亲密。您所需要做的就是将方括号更改为花括号。像这样:

conca = {c{1};c{2}};

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

conca = {B{1};B{3}}

这将为您提供相同的元胞数组。

关于arrays - 串联元胞数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15136829/

相关文章:

matlab - 二进制表示形式的两个整数相加

c++ - 是否有一种算法可以在排序数组中搜索不包括一个复杂度为 O(lgn) 的指定数字的元素?

java - Java 数组的迭代器

c - 如何从数组列表的中间删除一个字符?

android - Matlab audioread/audioplay 通过 Coder 转换为 C/C++

javascript - 隐藏包含空列的行

c++ - 创建一个非预定义大小的数组?

java - Matlab 图形用户界面自动化?

arrays - 从单元格的单元格数组中检索第一个值

arrays - 连接单元格