How to efficiently find index of matrix elements in another matrix
Find more posts tagged with
Sort by:
1 - 4 of
41
What about adding these 2 commands after what I already suggested?
[bool,y2] = ismember(x2,A);
[bool,z2] = ismember(x2,B);
Results are the same (y is the original approach you shared and y2 is the new one):
It is still more than 2 times faster:
Elapsed time is 8.715 seconds.
Elapsed time is 3.456 seconds.
Regards,
Roberta
@Manoj Kandukuri,
Are you willing to store only x results or do you also need y and z? Because in case you need only x, this solution is much faster:
x3 = unique(A(ismember(A,B)))
As a comparison, if you run these commands, which I created to replicate your scenario:
It is around 4 times faster with the second approach:
Elapsed time is 5.662 seconds.
Elapsed time is 1.344 seconds.
Regards,
Roberta