how to find elements in an array
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Chad Greene
il 18 Feb 2014
Commentato: Chad Greene
il 18 Feb 2014
Given this:
x = 1:100;
y = 201:300;
a = 250;
I know that
x(y==a)
will return 50, the value of x corresponding to the y index where y = a. Now if a has multiple elements, I'd like to find all the values of x corresponding to all the values of y where y equals any of the values in a. For example, if
a = [250; 215; 283];
I'd like to efficiently get the array [50; 15; 83]. How can I do this?
0 Commenti
Risposta accettata
Azzi Abdelmalek
il 18 Feb 2014
Modificato: Azzi Abdelmalek
il 18 Feb 2014
x = 1:100;
y = 201:300;
a = [250; 215; 283];
out=x(ismember(y,a))
Vedere anche
Categorie
Scopri di più su Whos in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!