|
"Matt J" wrote in message <jt4nse$ma$1@newscl01ah.mathworks.com>...
> "Mikael" wrote in message <jt4df7$hm9$1@newscl01ah.mathworks.com>...
> > Hello,
> > I have an time-efficiency issue using intersect:
> > [~,~,ib] = intersect(A, B);
> >
> > A and B are vectors.
> > A is a row-vector ~1x60
> > B a column-vector ~300x1
> >
> > This line is called thousands of times.
> > Do you have an idea how to speed it up ?
> =================
>
> How is this a time-efficiency issue? On my old dual core 32-bit laptop, I can execute the above 1000s of times in just a few seconds.
Yes, I should have said hundreds of thousands times!
I have realised this morning that some details could help:
A = a1:a2, with a1 =< a2 integers
B is sorted.
So, as a first approach:
[~,i1] = ismember(a1,B);
[~,i2] = ismember(a2,B);
ib = B(i1:i2);
Now this form is not faster but hopefully in a few minutes, I will find something efficient!
|