Index into a table using a vector of values
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Isabel Chen
le 5 Avr 2016
Commenté : Isabel Chen
le 5 Avr 2016
Suppose I have a table:
T =
var1 var2
a 1
b 2
c 2
d 3
e 4
f 4
g 4
and I am interested in the rows of T where var2 takes values 1, 3, or 4. Is there a direct way to subset into the table using the vector [1; 3; 4], instead of using a for-loop? To be clear, I am interested in obtaining the following output:
subT =
var1 var2
a 1
d 3
e 4
f 4
g 4
I don't see how I can get this using a logical expression. Any thoughts?
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 5 Avr 2016
Modifié(e) : Azzi Abdelmalek
le 5 Avr 2016
A=[5 1;7 3;12 4;47 4;6 4]
out=A(ismember(A(:,2),[1 3 4]),:)
Plus de réponses (0)
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!