Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*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 1999

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

Search the Archive

Re: problem with Part function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg18194] Re: problem with Part function
  • From: paulh at wolfram.com (P.J. Hinton)
  • Date: Mon, 21 Jun 1999 22:50:36 -0400
  • Organization: Wolfram Research, Inc.
  • References: <7kho9q$qop@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <7kho9q$qop at smc.vnet.net>, "Casubolo Dario" <bubbola at workline.it> writes:

> Just a little problem:
> I've a matrix of zeros, say:
> mat=Table[Table[0,{5}],{5}];
> then, I've a point in xy axys,
> xy={3,3};
> now, I want the position {3,3} of matrix becomes 1;
> if I write
> mat[[xy]]=1; or mat[[{3,3}]]=1; it doesn't work; only mat[[3,3]]=1 
> works, but I don't want rewrite all.
> I think I've to use something like Map, Thread, Apply or so, but I don't 
> know what and how exactely;
> please, someone help me.

You can use Apply[Sequence, #]& to blow away the list structure.  Here is an
example.

In[1]:=
mat = Table[Table[0, {5}], {5}]

Out[1]=
{{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0,
     0, 0}}

In[2]:=
mat[[Sequence @@ {3, 3}]] = 1

Out[2]=
1

In[3]:=
mat

Out[3]=
{{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 1, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0,
     0, 0}}

--
P.J. Hinton	
Mathematica Programming Group		paulh at wolfram.com
Wolfram Research, Inc.
Disclaimer: Opinions expressed herein are those of the author alone.


  • Prev by Date: Re: Version 4.0 - Importing TIF files
  • Next by Date: Re: Some problems with complex functions like Sqrt[z]
  • Previous by thread: Re: problem with Part function
  • Next by thread: Re: problem with Part function