Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否有从矩阵中获取特定元素的简写?说,我有一个矩阵m,我想得到元素(a, b)和(c, d)。我可以在一个表达式中做到这一点吗?
m
(a, b)
(c, d)
另一种选择(在我看来是一个更简单的选择)只是:
val=[m(a,b) m(c,d)];
是的。您可以使用sub2ind将下标列表转换为索引。这适用于任意数量的维度。从您的示例中,如果您想获取matrix(a, b)and matrix(c, d),则可以这样做:
sub2ind
matrix(a, b)
matrix(c, d)
values = matrix(sub2ind (size (matrix), [a c], [b d]))