optimization - MATLAB-making intersect faster -


let there 2 arrays {a,b} of size 1xn

i want find number of cases on same indices

the condition a(ii)==1 & b(ii)==0 satisfied.

i tried

casess= intersect( find(a==1),find(b==0 )) 

but slow.

i believe because intersect checks on every member if member of other group, still looking fastest solution smaller problem.

the number of cases condition true can computed with:

numcases = sum(a == 1 & b == 0); 

the expression a == 1 & b == 0 gives logical array can used, example, find indices condition true:

ind = find(a == 1 & b == 0); 

or directly access matrix same size via logical indexing:

c = zeros(size(a)); c(a == 1 & b == 0) = 5; 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -