MathGroup Archive 1995

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

Search the Archive

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


Richard Q. Chen <chen at fractal.eng.yale.edu> wrote:

>        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.

Always remember -- the heart of Mathematica is pattern matching.
How 'bout this:

In[1]:=
OddOnly[{odd_, even_, rest___}] := Join[{odd}, OddOnly[{rest}]];
OddOnly[singleton_] := singleton;

OddOnly //@ {{11,12,13,14,15},
             {21,22,23,24,25},
             {31,32,33,34,35},
             {41,42,43,44,45},
             {51,52,53,54,55}}
Out[3]=
{{11, 13, 15}, {31, 33, 35}, {51, 53, 55}}


        Tyler Perkins                   perkins at colorado.edu
        Boulder, Colorado




  • Prev by Date: Re: Functions, Part 1
  • Next by Date: Re(best answer)
  • 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?