Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Abhijith
Abhijith le 19 Août 2013
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.

Réponse acceptée

David Sanchez
David Sanchez le 19 Août 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.
  1 commentaire
Abhijith
Abhijith le 19 Août 2013
Thank you for your answer.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by