Clear Filters
Clear Filters

n=A(B) where A and B are matrices?

1 view (last 30 days)
Hello, I just tried to do the following operation,
>> B=full(B)
B =
5 1 8 3 2 8
9 9 8 8 3 6
1 1 1 4 2 5
4 7 4 9 2 2
>> A=full(A)
A =
1 8 2 6 5 9
4 3 6 7 1 2
2 5 3 7 3 8
>> A(B)
ans =
3 1 6 2 4 6
3 3 6 6 2 5
1 1 1 8 4 3
8 2 8 3 4 4
I would like to know what exactly has happened here. Thank you.

Accepted Answer

David Sanchez
David Sanchez on 19 Aug 2013
A(B) returns the value of the B(ith) element of A. The elements are counted column-wise, what means than in your case: A(1) = 1; A(2) = 4; A(3) = 2; A(4) = 8; A(5) = 3; ... A(18) = 8;
Now, if you take the matrix B as index, you get back a matrix whose elements are the elements of A in the position determined by the value of the element of B:
B(1) = 5
then, the first element of A(B) = A(5) = 3.
B(2) = 9
then, the second element of A(B) = A(9) = 3
B(3) = 1
then, the second element of A(B) = A(1) = 1
and so on.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!