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