Re: how to pick out alternating columns and rows in a matrix?
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg580] Re: [mg551] how to pick out alternating columns and rows in a matrix?
- From: perkins at colorado.edu (Tyler Perkins)
- Date: Mon, 20 Mar 1995 12:00:53 -0700
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