Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1995
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: how to pick out alternating columns and rows in a matrix?

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg577] Re: [mg551] how to pick out alternating columns and rows in a matrix?
  • From: hannibal at caesar.physik.uni-oldenburg.de (L. Hannibal)
  • Date: Mon, 20 Mar 1995 10:33:28 +0100 (NFT)

> eng.yale.edu>
> To: mathgroup at christensen.cybernetics.net
> Subject: [mg551] how to pick out alternating columns and rows in a matrix?
> Content-Length: 1249
> 
> 
> Hi,
> 	Suppose I have a matrix of even dimensions, I would like
> to form a matrix consisting of only the odd rows and columns of the
> matrix. A concrete example may make my request clearer:
> 
> In[2]:= MatrixForm[u=Array[a,{6,6}]]
> 
> Out[2]//MatrixForm= a[1, 1]   a[1, 2]   a[1, 3]   a[1, 4]   a[1, 5]   a[1, 6]
> 
>                     a[2, 1]   a[2, 2]   a[2, 3]   a[2, 4]   a[2, 5]   a[2, 6]
> 
>                     a[3, 1]   a[3, 2]   a[3, 3]   a[3, 4]   a[3, 5]   a[3, 6]
> 
>                     a[4, 1]   a[4, 2]   a[4, 3]   a[4, 4]   a[4, 5]   a[4, 6]
> 
>                     a[5, 1]   a[5, 2]   a[5, 3]   a[5, 4]   a[5, 5]   a[5, 6]
> 
>                     a[6, 1]   a[6, 2]   a[6, 3]   a[6, 4]   a[6, 5]   a[6, 6]
> 
> I would like to pick out the 1st, 3rd and 5th rows and columns.
> My current solution is embarassingly contorted. I would like to see
> some more elegant solutions to this.
> 
> Here is what I did:
> 
> In[3]:= First /@ Partition[Flatten[u],2];
> 
> In[4]:= Transpose[Partition[%,3]];
> 
> In[5]:= First /@ Partition[Flatten[%],2];
> 
> In[6]:= Transpose[Partition[%,3]];
> 
> In[7]:= MatrixForm[%]
> 
> Out[7]//MatrixForm= a[1, 1]   a[1, 3]   a[1, 5]
> 
>                     a[3, 1]   a[3, 3]   a[3, 5]
> 
>                     a[5, 1]   a[5, 3]   a[5, 5]
> 
> Thanks for any help.
> 
> Richard
> 
> 
Richard,

odd[u_]:=Array[u[[2 #1 -1,2 #2-1]]&,
          {Ceiling[Length[u]/2],Ceiling[Length[u[[1]]]/2]}]

works on any rectangular matrix.

Ludger.

*************************
Ludger Hannibal
Carl v. Ossitzky Universitaet
Oldenburg, 
Germany
************************


  • Prev by Date: Re: Functions, Part 1
  • Next by Date: Re: how to pick out alternating columns and rows in a matrix?
  • Previous by thread: Re: how to pick out alternating columns and rows in a matrix?
  • Next by thread: Re: how to pick out alternating columns and rows in a matrix?