Clear Filters
Clear Filters

Accessing to the position stored in a variable

1 view (last 30 days)
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)).

Accepted Answer

Walter Roberson
Walter Roberson on 10 Dec 2011
The below does not look like much, but it uses a powerful MATLAB facility:
t = num2cell(b);
  1 Comment
Mohsen  Davarynejad
Mohsen Davarynejad on 10 Dec 2011
Many thanks Walter, It's perfectly matches what I was looking for.

Sign in to comment.

More Answers (0)


Find more on Matrices and Arrays in Help Center and File Exchange


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!