Path: news.mathworks.com!not-for-mail
From: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
Newsgroups: comp.soft-sys.matlab
Subject: Re: compare two rows, from different matrices
Date: Fri, 8 Feb 2008 17:03:08 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 62
Message-ID: <foi20c$8e4$1@fred.mathworks.com>
References: <fohtuq$bog$1@fred.mathworks.com>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1202490188 8644 172.30.248.35 (8 Feb 2008 17:03:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 8 Feb 2008 17:03:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:450187


"Marcel " <JMarcel2@gmail.com> wrote in message <fohtuq$bog
$1@fred.mathworks.com>...
> Hello 
> 
> 
> I have a problem with comparing two rows of two differents
> matrices.
> I have matrix A, size is [1024,8]
> the size of matrix B is [7,8]
> Both matrix A and B store only binary numbers. 
> 
> I need to compare every row from A, with each row from B.
> For example :
> 1.row from A compare with 1. row from B
>                 then with 2.row from B
>                       ..
>                       ..
>                      with 7. row from B
> 
> then make another matrix TEMP with size [1024,8]
> The  row from B that is most similar to 1. row from A, give
> to the 1. row of TEMP 
> 
> 
> 2.row from A compare with 1. row from B
>                 then with 2.row from B
>                       ..
>                       ..
>                      with 7. row from B
> The  row from B that is most similar to 2. row from A, give
> to the 2. row of TEMP
> ..
> ..
> ..
> ..
> 1024.row from A compare with 1. row from B
>                    then with 2.row from B
>                         ..
>                         ..
>                         with 7. row from B
> The  row from B that is most similar to 1024. row from A,
> give to the 1024. row of TEMP
> 
> so I should have a new matrix TEMP , which contains from B rows
>  Can somoen help me, I have own script, but he just compare
> all elements from A with 1. row from B
> Thank you
----------
  I think the following should work:

 [ignore,ix] = min(A*(1-B.')+(1-A)*B.',[],2); % Find min in each row
 C = B(ix,:);

The matrix A*(1-B.')+(1-A)*B.' will be of size 1024 by 7 and each i,j entry will 
be a count of the number of differences between the i-th row of A and the j-
th row of B.  This is valid only if the values in A and B are all ones and zeros, 
as you stated.  In case two different rows of B are equally similar (have equal 
counts) to a row of A, the earliest one in B wins out.

Roger Stafford