Can I find set of values in larger set in one step?
Mostra commenti meno recenti
Hi,
I am working on a code that takes a very long time to implement, so I try to optimize it
If I look for a set of values (x) in a larger set (z), can I do that in a way faster than using for and find?
x=[1 2 3];
z=[10 2 1 5 7 .....];
thanks
10 Commenti
Walter Roberson
il 14 Ago 2022
ismember() with two outputs
the cyclist
il 14 Ago 2022
ismember is almost certainly the way to go, as @Walter Roberson says. A more specific answer could be given, if you tell us more specifically what output you want from the inputs x and z.
Walter Roberson
il 14 Ago 2022
For example are there multiple copies of the values, and is what you are looking for as output a cell array, one entry for each item in x, giving the indices in z ?
huda nawaf
il 15 Ago 2022
huda nawaf
il 15 Ago 2022
Modificato: huda nawaf
il 15 Ago 2022
x=[1 2 3];
z=[10 2 1 5 7];
z(ismember(z,x)) = []
huda nawaf
il 15 Ago 2022
If Bruno's method solves the problem, this works also:
x = [1 2 3];
z = [10 2 1 5 7];
z = setdiff(z, x, 'stable')
huda nawaf
il 15 Ago 2022
x=[1 2 3];
z=[10 2 1 5 7];
c=[9 4 2 1];
c(ismember(c,intersect(z,x)))=[]
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Choose a Solver in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!