Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*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 2000

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

Search the Archive

Re: extracting column data from 2D Matrix

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

In a message dated 5/7/2000 9:45:06 PM, krautschikc at intel.co.jp 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
>(1st
>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
>it
>each time? That is perhaps something like the following I had in mind:
>
>yindex= #*Table[i,{1,101,10}];
>columnIndex2=Append[{#1},yindex];
>
>This though doesn't seem to work even when I used:
>
>ToExpression[columnIndex2]
>
>or tried various other string to expression schemes.
>
>Also I like to average each 10 consequitive rows. That is I have written
>a
>RowMean function that generate the column vector of the 1000 elements.
>How
>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)
>but
>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

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

% == %%

To add columns with averages:

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


Bob

BobHanlon at aol.com


  • 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