On 10/16/2010 10:59 PM, Aidy wrote:
> hello friends,
>
> I have 2 matrices , A and B,
>
>
> A = [ 1 7 1 4
> 2 3 1 4
> 2 4 1 4
> 2 5 1 4
> 2 6 1 4]
>
> B = [ 1 1 4 7
> 5 2 4 1
> 8 5 3 4]
>
>
> I want to get the intersection of rows where all elements are the same in rows of A and B , even though in different order.
>
> So from A and B, i'd wish to obtain:
>
> A_B =
> [1 7 1 4;
> 2 5 1 4]
>
> This is so since the corresponding rows in B are ' 1 1 4 7' and ' 5 2 4 1'.
>
> take care
> Aiden
When all else fails, one can simply write a loop (OMG!), yes, a loop.
When not loop over A, check if each row matchs any of the rows in B?
this is O(n^3), not good, but for HW or small problem size, not a problem.
For one row check against anothe row check, use something like:
a =
1 2 3 4
b =
4 3 1 2
if ( length(intersect(a,b))==length(a)), fprintf('yes\n'); end
yes
(untill a smarter solution is found, that is)
Nasser
