MATLAB:元胞数组cell

与普通数组的区别:元胞数组的每个元素可以是不同的类型,可以是矩阵,字符串,结构体,。。就是一个加强的数组。。

创建元胞数组:

>> c_array(1,1)={[1 2;3 4]}%矩阵
>>> c_array(1,2)={"kobe,it's kobe!!!"}%字符串
>>> c_array(2,1)={[1,2,3,4]};%list
>>> c_array(2,2)={struct('name','kobe','age',21)}
>c_array =

  2×2 cell 数组

    {2×2 double}    {["kobe,it's kobe!!!"]}
    {1×4 double}    {1×1 struct           }

注意()与{}的区别:

():返回该位置的元素类型信息

{}:返回该位置的具体数据

>> c_array(1,1)

ans =

  1×1 cell 数组

    {2×2 double}

>> c_array(1,2)

ans =

  1×1 cell 数组

    {["kobe,it's kobe!!!"]}

>> c_array{1,1}

ans =

     1     2
     3     4

>> c_array{1,2}

ans = 

    "kobe,it's kobe!!!"

猜你喜欢

转载自blog.csdn.net/heimu24/article/details/81146399
今日推荐