       Re: problem with Part function

• To: mathgroup at smc.vnet.net
• Subject: [mg18193] Re: problem with Part function
• From: "David Keith" <dkeith at hevanet.com>
• Date: Mon, 21 Jun 1999 22:50:35 -0400
• Organization: Hevanet Communications
• References: <7kho9q\$qop@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi Dario,

The problem is that Part, seen here as mat[[x,y]], wants to receive its
arguments as a sequence, not imbeddded in a list. mat[[{x,y}]] really means
{ mat[[x]], mat[[y]] }, which is a list of elements.

You can use

mat[[x,y]] = newValue

or, if you really want to keep the points as two-element lists, say xy, use
either

mat[[ xy[],xy[] ]]  which is horribly clumsy,

or

mat[[ Sequence@@xy ]]   where xy is some {x,y}.

The latter method uses Apply (given here as @@ ) to replace the head of the
List xy with Sequence which splices it into Part.

Here is an example:

In:=
m = Table[0, {3}, {3}]
Out=
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}
In:=
m
Out=
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}
In:=
m[[2, 2]] = 2
Out=
2
In:=
m
Out=
{{0, 0, 0}, {0, 2, 0}, {0, 0, 0}}
In:=
xy = {3, 3}
Out=
{3, 3}
In:=
m[[Sequence @@ {3, 3}]] = 3
Out=
3
In:=
m
Out=
{{0, 0, 0}, {0, 2, 0}, {0, 0, 3}}

-- Dave

Casubolo Dario wrote in message <7kho9q\$qop at smc.vnet.net>...
>
>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;
>THANK YOU
>
>Dario Casubolo
>email: bubbola at workline.it
>
>
>

```

• Prev by Date: Re: Mathematica 2.2 on iMac?
• Next by Date: Re: Version 4.0 - Importing TIF files
• Previous by thread: Re: problem with Part function
• Next by thread: Re: problem with Part function