[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: using find function to wrap set functions
From: |
Francesco Potortì |
Subject: |
Re: using find function to wrap set functions |
Date: |
Wed, 26 Oct 2011 16:14:34 +0200 |
>> I would like to use "find" with some set functions, because a for loop takes
>> too much time. For example, I have a large array aa (100000,10) where each
>> row has 10 numbers. I want to use the complement function to find all rows
>> that contain the values [12 54 77]. This code is too slow:
>>
>> for ix = 1:rows(aa)
>> if (columns(complement (aa(ix,:), [12 54 77])) == 0)
>> ...save ix...
>> endif
>> endfor
>>
>> I would like to wrap this in a find function, but I don't know the syntax
>> for this.
>>
>> find(columns(complement (aa(:,:), [8 43])) == 0); does not work.
>>
>
>This solution is probably completely stupid, but what about
>
>find(sum(aa==12 | aa==54 | aa==77, 2) == 3)
This only works if there are not duplicates in each row. But this one
(untested) should work:
find(all(any(aa'==12), any(aa'==54), any(aa'==77)))
--
Francesco Potortì (ricercatore) Voice: +39.050.315.3058 (op.2111)
ISTI - Area della ricerca CNR Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa Fax: +39.050.315.2040
(entrance 20, 1st floor, room C71) Web: http://fly.isti.cnr.it