Re: problem with Part function
- To: mathgroup at smc.vnet.net
- Subject: [mg18190] Re: [mg18172] problem with Part function
- From: BobHanlon at aol.com
- Date: Mon, 21 Jun 1999 22:50:33 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Dario, Use ReplacePart mat = Table[Table[0, {5}], {5}]; xy = {3, 3}; mat = ReplacePart[mat, 1, xy] {{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}} xy2 = Table[{n, n}, {n, Length[mat]}]; mat = ReplacePart[mat, 1, xy2] {{1, 0, 0, 0, 0}, {0, 1, 0, 0, 0}, {0, 0, 1, 0, 0}, {0, 0, 0, 1, 0}, {0, 0, 0, 0, 1}} val = Range[Length[mat]]; valPos = Table[{n}, {n, Length[mat]}]; mat = ReplacePart[mat, val, xy2, valPos] {{1, 0, 0, 0, 0}, {0, 2, 0, 0, 0}, {0, 0, 3, 0, 0}, {0, 0, 0, 4, 0}, {0, 0, 0, 0, 5}} Bob Hanlon In a message dated 6/20/99 2:27:38 AM, bubbola at workline.it writes: >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; >