Accessing to the position stored in a variable
2 次查看(过去 30 天)
显示 更早的评论
Suppose I have a matrix, A=rand(5,5) and an array, b=[2,3]. How can I extract the A(2,3) element? I know a simple solution is A(b(1), b(2)), but the problem is that I may end up with a high dimensional A matrix and I do not want to write something like: A(b(1), b(2), b(3),…., b(n)).
0 个评论
采纳的回答
Walter Roberson
2011-12-10
The below does not look like much, but it uses a powerful MATLAB facility:
t = num2cell(b);
A(t{:})
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!