MathGroup Archive 2000

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

Search the Archive

Re: extracting column data from 2D Matrix

  • To: mathgroup at
  • Subject: [mg23442] Re: [mg23412] extracting column data from 2D Matrix
  • From: BobHanlon at
  • Date: Wed, 10 May 2000 02:32:23 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

In a message dated 5/7/2000 9:45:06 PM, krautschikc at writes:

>I have a 2D Matrix of say 101 columns and 1000 rows. Let's call the data
>matrix xyDATA. The first column represents the X coordinate and all other
>columns represent Y coordindates for different input conditions.
>Let's say I need to extract every 10th y column as well as the X column
>column) so I can plot the data in another program. I have been using the
>following expression for the extraction process:
>colmnIndex={#1, #11,#21,#31#41,#51,#61,#71,#81,#91,#101};
>xy10 = columIndex & @@@ xyDATA;
>How do I automate the process for the column Index without have to type
>each time? That is perhaps something like the following I had in mind:
>yindex= #*Table[i,{1,101,10}];
>This though doesn't seem to work even when I used:
>or tried various other string to expression schemes.
>Also I like to average each 10 consequitive rows. That is I have written
>RowMean function that generate the column vector of the 1000 elements.
>do I then insert after each 10 y column the columns that holds the average?
>So the matrix now grows from 101 colums to 111 colums (still 1000 rows)
>the averaged columns need to be inserted at (12,22,33,...).

Output has not been included below:

nbrRows = 4; nbrCols = 8; initY = 2; colSpacing = 3;

xValues = Array[x, nbrRows];

yValues = Array[y, {nbrRows, nbrCols - 1}];

xyData = Transpose[Join[{xValues}, Transpose[yValues]]];

In version 4

xyData[[All, Join[{1}, Range[initY, nbrCols, colSpacing]]]]

In version 3

  Part[Transpose[xyData], Join[{1}, Range[initY, nbrCols, colSpacing]]]]

% == %%

To add columns with averages:

(# /. y_?VectorQ :> (Sequence @@ Join[y, {(Plus @@ y)/Length[y]}])) & /@ 
        Partition[#, colSpacing] & /@ Transpose[Rest[Transpose[xyData]]]]]]


BobHanlon at

  • Prev by Date: Re: extracting column data from 2D Matrix
  • Next by Date: evaluation sequence
  • Previous by thread: Re: extracting column data from 2D Matrix
  • Next by thread: Re: extracting column data from 2D Matrix