Re: matrix
- To: mathgroup at smc.vnet.net
- Subject: [mg107098] Re: matrix
- From: Ray Koopman <koopman at sfu.ca>
- Date: Tue, 2 Feb 2010 06:54:19 -0500 (EST)
- References: <hk8nkh$8fs$1@smc.vnet.net>
On Feb 2, 12:26 am, Piotr Munik <piotr.mu... at gmail.com> wrote:
> I have matrix M and matrix N
> for example
> M={{*1*,2},{3,4},{*5*,6},{7,8}}
> N={{*1*,8},{*5*,0},{9,7}}
> (dimension is diffrent)
> I need to make new matrixes which include only this rows from matrix M and
> matrix N for which firsts elements are the same in both matrix (M and N).
> so I need
> M1={{1,2},{5,6}}
> N1={{1,8},{5,0}}
> Elements of matrix are real (not always integer)
> Please for help
> Peter
m = {{1,2},{3,4},{5,6},{7,8}};
n = {{1,8},{5,0},{9,7}};
mn = Alternatives @@ Intersection[
m1 = m[[All,1]], n1 = n[[All,1]] ]
m1 = Pick[m,m1,mn]
n1 = Pick[n,n1,mn]
1|5
{{1,2},{5,6}}
{{1,8},{5,0}}