Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: I want to merge two matricies based on a column, what is best way?
Date: Sun, 10 Oct 2010 20:48:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 15
Message-ID: <i8t8q3$8h4$1@fred.mathworks.com>
References: <i8t6bc$7ih$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1286743683 8740 172.30.248.37 (10 Oct 2010 20:48:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 10 Oct 2010 20:48:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:677275

"BobC Cadenza" <bobc@mailinator.com> wrote in message <i8t6bc$7ih$1@fred.mathworks.com>...
> I have two matricies, with one column in each that is unique and I will call the index.  I want to merge the matricies so that I have a new matrix that contains each row from each matrix that each have the same index.  How can i do this?  Below is a simple example.  Thanks in advance.
> 
> mat1 = [[1.2 4.2 datenum(today);5.2 2.4 datenum(today-1);2.4 1.2 datenum(today-3)];
> 
> mat2 = [[1.2 34.2 datenum(today)32.4 11.2 datenum(today-3)];
> 
> result =  [[1.2 4.2 1.2 34.2 datenum(today);2.4 1.2 32.4 11.2 datenum(today-3)];
- - - - - - - - - -
  Your description leaves much to be desired as to its clarity.  This is my best guess of what you mean:

 [c,i1,i2] = intersect(mat1(:,3),mat2(:,3));
 result = [mst1(i1,1:2),mat2(i2,1:2),c];

Roger Stafford