Removing specific elements from array

11 vues (au cours des 30 derniers jours)
ng jun Quan
ng jun Quan le 28 Avr 2019
Commenté : ng jun Quan le 28 Avr 2019
Lets assume i have
a = [1 1 3 5];
c = [1 5];
i want to remove c from a and the output should be a = [1 3]
a = setdiff(a,c) %this works but it removes both the '1' .

Réponse acceptée

Stephen23
Stephen23 le 28 Avr 2019
Modifié(e) : Stephen23 le 28 Avr 2019
>> a = [1,1,3,5];
>> c = [1,5];
>> [X,Y] = ismember(c,a);
>> a(Y(X)) = []
a =
1 3

Plus de réponses (0)

Catégories

En savoir plus sur Data Types 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