MATLAB: Indexing a matrix with an array

arrayindexMATLABmatrix

Let's say I have a 4×4 matrix A. I can then get the item in place [2,3] by typing A(2,3).
Now let's say I have an array I=[2,3]. I would like to be able to write something like A(I) to get the same result as above. How could I do that?
Thanks.

Best Answer

Use a cell array, e.g.:
C = {2,3}; % use NUM2CELL(I) if required.
A(C{:})
Tested:
>> A = rand(4,4)
A =
0.340974 0.252464 0.596849 0.800738
0.064510 0.270160 0.242550 0.518083
0.546270 0.318667 0.581832 0.409444
0.814609 0.675596 0.588558 0.353607
>> C = {2,3};
>> A(C{:})
ans = 0.24255