cell 和cell array

发布时间 2023-03-28 11:50:26作者: hayden_william

最近写matlab程序和处理数据,用到了cell 和struct ,简单记录一下。

从cell array 删除cell

用{}不能删除,要用(),赋予[]。

>> s.a=1
s = 
  包含以下字段的 struct:

    a: 1
>> s.b=1
s = 
  包含以下字段的 struct:

    a: 1
    b: 1
>> c={s s s}
c =
  1×3 cell 数组
    [1×1 struct]    [1×1 struct]    [1×1 struct]
>> c{1}=[]
c =
  1×3 cell 数组
    []    [1×1 struct]    [1×1 struct]
>> c={s s s}
c =
  1×3 cell 数组
    [1×1 struct]    [1×1 struct]    [1×1 struct]
>> c(2)=[]
c =
  1×2 cell 数组
    [1×1 struct]    [1×1 struct]

用[]和{}拼接元胞数组的区别

>> C = {1, 2, 3; 4, 5, 6; 7, 8, 9}
C =
  3×3 cell 数组
    [1]    [2]    [3]
    [4]    [5]    [6]
    [7]    [8]    [9]
>> c1=C(1,:)
c1 =
  1×3 cell 数组
    [1]    [2]    [3]
>> c2=C(2,:)
c2 =
  1×3 cell 数组
    [4]    [5]    [6]
>> c3=C(3,:)
c3 =
  1×3 cell 数组
    [7]    [8]    [9]
>> D1=[c1;c2;c3]
D1 =
  3×3 cell 数组
    [1]    [2]    [3]
    [4]    [5]    [6]
    [7]    [8]    [9]
>> D1={c1;c2;c3}
D1 =
  3×1 cell 数组
    {1×3 cell}
    {1×3 cell}
    {1×3 cell}