Element-wise set operations

4 vues (au cours des 30 derniers jours)
Gabriel Stanley
Gabriel Stanley le 2 Déc 2022
Commenté : Gabriel Stanley le 3 Déc 2022
Given twovectors A & B, I'm trying to figure out how to get a numel(A)-by-numel(B) logical array C wherein C(i) is the result of ismember(B',A(i)) without using a for loop. I've tried feeding repmat'ed and tranposed versions of A & B into ismember, but to no avail.
How can I achieve the same result as
A = randi(11, [500 1]);
B = randi(10, [250 1]);
C = false(500,250)
for i = 1:numel(A)
C(i) = ismember(B',A(i));
end
without the for loop? If the answer is arrayfun, is that really any faster than a for loop?

Réponse acceptée

Voss
Voss le 2 Déc 2022
  1 commentaire
Gabriel Stanley
Gabriel Stanley le 3 Déc 2022
It works, but I don't understand why it works while the un-looped ismember use didn't. If I have time later I'll try to dig into that and improve my understanding. In the meantime, thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by