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

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

Search the Archive

Re: Subscripting Matrices (Syntax Question ?)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg14249] Re: Subscripting Matrices (Syntax Question ?)
  • From: Harald Giese <giese at dkrz.de>
  • Date: Mon, 12 Oct 1998 13:51:34 -0400
  • Organization: Institut fuer Meereskunde, Universitaet Hamburg
  • References: <6vf6bj$djg@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Arthur Chtcherba wrote:
> ...
> I am constructing a matrix (whose dimensions I do not know in advance),
> and later
> on I want to index various elements in the array.
> 
> An index is in a form of a list, and want to use with a matrix but for
> example
>   mtx[[{1,3,2}]] = 0
> will not set element  mtx[1,3,2].
> ...


Hi Arthur,

mtx[[{1,3,2}]] = 0 does its job correctly:

In[2]:=
mtx=Range[5]
Out[2]=
{1,2,3,4,5}
In[3]:=
mtx[[{1,3,2}]] = 0
Out[3]=
0
In[4]:=
mtx
Out[4]=
{0,0,0,4,5}

However, "mtx[1,3,2]" is not the correct way of referencing matrix (i.e.
List-) elements in Mathematica. Instead type
  {mtx[[1]], mtx[[3]], mtx[[2]]}
or 
  mtx[[{1,3,2}]]


Regards,
Harald

-- 
Harald Giese
Email: giese at dkrz.de
Phone: +49 (0)40 4123 5796; Fax: +49 (0)40 5605724 Institut fuer
Meereskunde der Universitaet Hamburg (Institute of Oceanography of the
University of Hamburg) Troplowitzstrasse 7, D-22529 Hamburg


  • Prev by Date: Re: graphing implicit function
  • Next by Date: Re: from Compositions to trees
  • Previous by thread: Subscripting Matrices (Syntax Question ?)
  • Next by thread: Re: Re: Outputting Strings to a file