Finding values (array) within a cellarray in matlab -


i trying find more efficient way of finding index of array within cellarray other using 'for' loops. problem follows:

a = [6,3] b = {[1,10];[1,8,10];[8,10];[2,8];2;[2,4,5];[2,4];[];[3,6];[3,4,6];6;[3,5,6];[6,9];[1,6,9];[1,6,7,9]} 

i need find index of 'a' within 'b'. current method works quite slow , cumbersome when increase size of 'b' case. i'm not interested in order of array, contents same why use 'setxor' method. code below shows example of how this.

for num = 1:size(b,1)            new_array(num,1) = isempty(setxor(a, b{num,1}));     if (new_array(num,1) == 1)        indexofarray = num;         break;      end; end; 

is there better way of doing this? in advance, vincent

it's easy cellfun:

find(cellfun(@(x) isempty(setxor(a,x)), b)) 

if want first coincidence, use

find(cellfun(@(x) isempty(setxor(a,x)), b), 1) 

this uses definition of coincidence, in terms of setxor.

thanks @dan , @dennisjaheruddin constructive comments, have been incorporated answer.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -