Effacer les filtres
Effacer les filtres

Index Vector Operation in Matlab

8 vues (au cours des 30 derniers jours)
Johan Johan
Johan Johan le 26 Août 2019
Commenté : James Tursa le 26 Août 2019
If the matrix A and the vector b
A = 5×5
13 2 3 3 10
14 5 15 7 1
2 9 15 14 13
14 15 8 12 15
10 15 13 15 11
b=[1 2 3 4 5]
and
>> C=A(b)
ans =
13 14 2 14 10
How to get element C by index in vector A(b) ?
  4 commentaires
Johan Johan
Johan Johan le 26 Août 2019
I corrected the mistake.
James Tursa
James Tursa le 26 Août 2019
Please restate your question. What do you mean by "get element C by index in vector A(b)"? Are you trying to do something like A(b)(2) to get at the 2nd element of C directly? If so, you cannot use that syntax in MATLAB.

Connectez-vous pour commenter.

Réponse acceptée

Jon
Jon le 26 Août 2019
Actually A(b) with the example you have given will return [13 14 2 14 10]. That is the elements are taken from the first column of A. Note that using linear indexing (indexing a two dimension array with a vector of indices, rather the pairs of indices) will provide the elements columnwise.
I'm not clear whether this is what you are asking. What do you mean by get element C by index in vector A(b) ?

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