Effacer les filtres
Effacer les filtres

Is there a more efficient way to compute this other than using a loop ?

2 vues (au cours des 30 derniers jours)
Rayan Glus
Rayan Glus le 31 Mai 2021
Commenté : Rayan Glus le 31 Mai 2021
Hello,
Say, vectors a and b have different sizes. I wonder if there is a simpler and more efficient way of writing the lines below.
b = [1 3 4 7 8 10 2 5 6];
a = [2 3 9];
for ii = 1:length(a)
b(b==a(ii))=[];
end
Output:
b = 1 4 7 8 10 5 6
Thanks!

Réponse acceptée

Matt J
Matt J le 31 Mai 2021
Modifié(e) : Matt J le 31 Mai 2021
b=setdiff(b,a,'stable')

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements 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