MATLAB如何将一个数组的值分别赋给另一个数组
展开全部
对于一个矩阵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]
>> 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]
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询