Effacer les filtres
Effacer les filtres

Indexing matrix from array

1 vue (au cours des 30 derniers jours)
Inna Pelloso
Inna Pelloso le 25 Mar 2022
Commenté : Inna Pelloso le 25 Mar 2022
Hi,
I have A = [1:3; 4:6; 7:9] and an index B = [1;0;1].
How can I extract from each column of A the values at are equal to 1 in B?
I want C = [1:3;7:9]. (I am trying to avoid having to use repmat for B)
Thank you!
IP

Réponse acceptée

David Hill
David Hill le 25 Mar 2022
A = [1:3; 4:6; 7:9];
B = logical([1;0;1]);
C=A(B,:);
  1 commentaire
Inna Pelloso
Inna Pelloso le 25 Mar 2022
Thank you! I forgot to format the index as logical!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by