森之张卫东 发表于 2015-8-9 16:06

元胞数组的数据获得


元胞数组的数据获得
    从元胞数组中读取数据,可保存为一个标准的数组或一个新的单元数组,或取出数组进行计算。元胞数组中数据的访问,可通过元胞内容的下标进行,用元胞数组名加大括号{}。大括号中数值表示元胞的下标。如a{1,2}表示元胞数组中第一行第二列的元胞。
>> a={20,'matlab';ones(2,3),1:3}
a =
   [            'matlab'
      
>> str=a(1,2)
str =
    'matlab'
>> class(str)
ans =
cell
>> str=a{1,2}
str =
matlab
>> class(str)
ans =
char
()和{}有着本质的区别,大括号用于表示元胞的内容,小括号表示指定的元胞。
a =
   [            'matlab'
      

>> a{2,1}(2,2)

ans =

   0.9134

>> a{2,1}(2,3)

ans =

   0.0975

>> a{1,2}(2)

ans =

a

页: [1]
查看完整版本: 元胞数组的数据获得