Hi. I have a two-dimensional array Z of size 10x15, and two vectors, A = [1 2 4] and B = [3 2 1]. Using A and B, I want to access the following elements in Z: Z(1,3), Z(2,2), Z(4,1) only
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ammar Gharaibeh
le 21 Nov 2017
Modifié(e) : Stefano Francavilla
le 21 Nov 2017
Hi. I have a two-dimensional array Z of size 10x15, and two vectors, A = [1 2 4] and B = [3 2 1]. Using A and B, I want to access the following elements in Z: Z(1,3), Z(2,2), Z(4,1) only. I tried using Z(A,B) but this will give me all combinations of elements (i.e. Z(1,3), Z(1,2), Z(1,1), Z(2,3), ...). Any idea how to do this.
0 commentaires
Réponse acceptée
Stefano Francavilla
le 21 Nov 2017
Modifié(e) : Stefano Francavilla
le 21 Nov 2017
I think you get a submatrix where the elements you are looking for are in the main diagonal: use diag(Z(A,B))
0 commentaires
Plus de réponses (1)
Voir également
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!