Remove rows in a matrix not having same element

24 vues (au cours des 30 derniers jours)
subhashree priyadarshini
subhashree priyadarshini le 2 Oct 2020
I am having a matrix
A =[1 2 3;
1 2 6;
1 2 7;
1 3 6;
1 3 7;
1 6 7;
2 3 6;
2 3 7;
2 6 7;
3 6 7]
I need the rows having element 2 means final matrix should be
A =[1 2 3;
1 2 6;
1 2 7;
2 3 6;
2 3 7;
2 6 7]

Réponse acceptée

Mario Malic
Mario Malic le 2 Oct 2020
This should work
Loc = ismember(A, 2)
idx = any(Loc,2)
B = A(idx, :)

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices 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