I am finding that a lot of time spent in my matlab function is in this code:
intersect(freq_bins, our_bins);
Both can be rather large vectors, and are comprised of only integers. I just need to know which integers are in both. This is truly the primitive purpose of intersect(), so I suspect that the answer is: it doesn’t get any better. But maybe someone has some suggestions.
intersectcallsismember. In your case, you don’t need all the complicated checks thatintersectdoes, so you can save some overhead and callismemberdirectly (note: I made sure to call both functions before timing them):You can make this even faster by calling
ismembc, the function that does the actual testing, directly. Note thatismembcrequires sorted arrays (so you can drop the sort if your input is sorted already!)