matlab - Is there a function like "ismember" but more efficient? -


for example,a number set.b elements.

i want test whether number in b element of set a.

i know matlab function "ismember" ,but it's not fast enough when use 1 million times.

b=[1,2,9,100]; a=[1,2,3,4,5,6,7,8,9]; tic;for ii=1:1e6,ismember(b,a);end;toc elapsed time 45.714583 seconds. 

i want return [1,1,1,0],because 1,2,9 in set a,while 100 not.

do know functions ismember or ways more efficient "ismember"?

you can use mex version, i.e. ismemberoneoutput. mex version faster.

b=[1,2,9,100]; a=[1,2,3,4,5,6,7,8,9]; tic;for ii=1:1e5,ismember(b,a);end;toc %elapsed time 9.537219 seconds. on pc  % must sorted!!! in example sorted, % no need here. tic;for ii=1:1e5,builtin('_ismemberoneoutput',b,a);end;toc %elapsed time 0.376556 seconds. on pc 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -