Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: tablename[[x]]= xth row, how to get xth column

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88605] Re: tablename[[x]]= xth row, how to get xth column
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 9 May 2008 07:16:44 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <g00v0k$gl7$1@smc.vnet.net>

cimon wrote:

> a very simple question, "sometablename[[X]]"  gives me the Xth row of
> table , like below.
> 
>  f = {{1, 2, 3, 4}, {1, 4, 6, 77}}
>  {{1, 2, 3, 4}, {1, 4, 6, 77}}
> f[[1]]
>  {1, 2, 3, 4}
> 
> 
> I am not able to find the syntax that can give me Xth column of a
> table.  i dont want to transpose it and use. and I tried #,

f = {{1, 2, 3, 4}, {1, 4, 6, 77}};

f[[All, 2]]

(*Returns the second column without explicitly transposing. Read it as: 
"Take all the rows and for each of these rows take only the second 
element"*)

{2, 4}

(*Similarly, the following extracts the third element of the second row 
only*)

f[[2, 3]]

6

You should read the short tutorial titled "Getting Pieces of Lists" 
available in the documentation center or online at

http://reference.wolfram.com/mathematica/tutorial/GettingPiecesOfLists.html

Regards,
-- Jean-Marc



  • Prev by Date: Re: 2 domain PDE, NDSolve
  • Next by Date: Re: Re: Point Symbol and Mesh
  • Previous by thread: Re: tablename[[x]]= xth row, how to get xth column
  • Next by thread: 2 domain PDE, NDSolve