【发布时间】:2021-11-17 13:18:00
【问题描述】:
我在 MATLAB 中创建了一个 3x3 矩阵,其中矩阵的每个元素都是一个列向量。当我尝试访问矩阵中的列向量之一的元素时,我遇到了一些困难。
syms a b c real
Cube = sym('K', [3,3])
K1_1 = [a; b; c];
K1_2 = [a; b; c];
K1_3 = [a; b; c];
K2_1 = [a; b; c];
K2_2 = [a; b; c];
K2_3 = [a; b; c];
K3_1 = [a; b; c];
K3_2 = [a; b; c];
K3_3 = [a; b; c];
for i = 1:3
for j = 1:3
x = Cube(i,j);
K1_1(3,1) % this does not give an error
x
x(3,1) % this gives an error
end
end
这是上面代码的输出:
Cube =
[ K1_1, K1_2, K1_3]
[ K2_1, K2_2, K2_3]
[ K3_1, K3_2, K3_3]
ans =
c
x =
K1_1
Error using sub2ind (line 52)
Out of range subscript.
Error in sym/subsref (line 766)
R_tilde = sub2ind(size(L), Idx.subs{:});
Error in MainSimFile2 (line 22)
x(3,1)
我成功地将x 设置为矩阵的一个元素,它是一个列向量。但是,当我尝试访问列向量的元素时出现错误。
如何设置这个矩阵?
【问题讨论】:
标签: matlab matrix symbolic-math