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: [mg588] Re: [mg551] how to pick out alternating columns and rows in a matrix?
  • From: Count Dracula <lk3a at kelvin.seas.virginia.edu>
  • Date: Wed, 22 Mar 1995 08:49:22 -0500

Here's a definition for a function to select odd(default) or even (with
sel = EvenQ) rows and columns of a matrix:

altrowcol[(m_)?MatrixQ, sel_:OddQ] := m[[Apply[Sequence, (Select[Range[#1], sel] & ) /@ Dimensions[u]]]]

Example usage:

In[1]:= u = Array[a, {6, 7}];

In[2]:= altrowcol[u]//MatrixForm

Out[2]//MatrixForm= a[1, 1]   a[1, 3]   a[1, 5]   a[1, 7]

                     a[3, 1]   a[3, 3]   a[3, 5]   a[3, 7]

                     a[5, 1]   a[5, 3]   a[5, 5]   a[5, 7]

In[3]:= altrowcol[u, EvenQ] //MatrixForm

Out[3]//MatrixForm= a[2, 2]   a[2, 4]   a[2, 6]

                     a[4, 2]   a[4, 4]   a[4, 6]

                     a[6, 2]   a[6, 4]   a[6, 6]



 ___________________________________________________________________________________
 Levent Kitis           lk3a at cars.mech.virginia.edu    lk3a at kelvin.seas.virginia.edu
 University of Virginia  Department of Mechanical, Aerospace and Nuclear Engineering  
 ___________________________________________________________________________________



  • Prev by Date: Fonts for math eqns in Davis,Porta&Uhl
  • Next by Date: Integration Bug in Mathematica
  • 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?