对于一个矩阵A,可以连续赋值,如
>> A(1:3)=1:2:5
A =
1 3 5
对于cell数组,连续赋值可以用一下格式
例1:赋以连续数字
>> test=cell(1,3);
>> test(1,1:3)=num2cell(1:3:9)
test =
[1] [4] [7]
cell数组中每一元素都是一个cell结构的,所以可以连续索引cell单元,赋以连续的cell结构的数据。注意不能用内容索引,即
大括号{ },如test{1:3},会报错
>> test{1:3}=num2cell(1:3:9)
The right hand side of this assignment has too few values to satisfy
the left hand side.
>> test{1:3}=1:3:9
The right hand side of this assignment has too few values to satisfy
the left hand side.
例2:
>> test(1:3)={1,'b','c'}
test =
[1] 'b' 'c'
例3:赋以相同值
>> test(1:3)={0}
test =
[0] [0] [0]