trying to use ismember to find a row in a large matrix
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a matrix A that as three columns A= [1 2 0.5555; 1 2 0.4555; 1 1 0.5555] I have a matrix B that is 7000x3 I want to find all the indx of B where the first row of A, A(1,:) resides.
I tried using ismember and it only returns the indx of the last row it finds in B.
[tf,indx]=ismember(A(1,:),B,'rows')
tf =
1
indx =
3212
I want all the indx rows not just the last. Everything I've read about ismember suggests that this should give me all the indx. Can you tell me what I'm doing wrong? or propose an alternate solution? By the way I'm running ver. R2009a.
Thanks, John.
0 Commenti
Risposta accettata
Walter Roberson
il 13 Apr 2013
[tf, loc] = ismember(A, S, ...) returns an array loc containing the highest index in S for each element in A that is a member of S. For those elements of A that do not occur in S, ismember returns 0.
R2013a onward change the "highest" to "lowest"; see http://www.mathworks.com/help/matlab/ref/ismember.html and also the 'legacy' option there for that detail.
Either way, only a single value will be returned.
If you want all the indices, the trick is to reverse the order of the operands
tf = ismember(B, A(1,:), 'rows');
indx = find(tf);
Also, as per usual, be very cautious when comparing floating point values; see http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical 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!