Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: compare two rows, from different matrices

Subject: compare two rows, from different matrices

From: Marcel

Date: 08 Feb, 2008 15:54:02

Message: 1 of 5

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


Subject: Re: compare two rows, from different matrices

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 08 Feb, 2008 16:48:25

Message: 2 of 5

In article <fohtuq$bog$1@fred.mathworks.com>,
Marcel <JMarcel2@gmail.com> wrote:
>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.

>The row from B that is most similar to 1. row from A, give
>to the 1. row of TEMP

What test should be used to determine what is "most similar"?
Does it just involve counting the number of positions at which
the contents are the same, or does it involve examining -which-
positions are the same? For example, is 00001111 "more similar"
to 00011110 or to 10001110, or are they the same similarity?
(the two have the same number of positions different, but for
00011110 the 1 has moved four places left and for 10001110
the 1 has moved 7 places left.)
--
   "No one has the right to destroy another person's belief by
   demanding empirical evidence." -- Ann Landers

Subject: Re: compare two rows, from different matrices

From: Randy Poe

Date: 08 Feb, 2008 16:55:42

Message: 3 of 5

On Feb 8, 10:54 am, "Marcel " <JMarc...@gmail.com> wrote:
> 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

Then perhaps you need a second loop which
chooses the row of B. Sounds like the structure
should be something like this:

for rowA = 1:1024
   for rowB = 1:7
      compare A(rowA,:) and B(rowB,:)
   end
   store winner in TEMP at rowA
end

            - Randy

Subject: Re: compare two rows, from different matrices

From: Marcel

Date: 08 Feb, 2008 17:03:07

Message: 4 of 5

the most similar means for example
row from A is 1111000 1.row from B 11100000
                       2.row.........00000111
                       3.row 00011100
                       so the program shoul d chose number 1

or 10101010 is row from A and there is 1. from B 10001010
                                          2. from B 10101000
there are equal numebr of diferrents...so program should
choose the first one..He following the order of rows

Subject: Re: compare two rows, from different matrices

From: Roger Stafford

Date: 08 Feb, 2008 17:03:08

Message: 5 of 5

"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


Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
compare two rows from different matrices Marcel 08 Feb, 2008 10:55:08
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics