Re: Replacing elements in matrix.

• To: mathgroup at smc.vnet.net
• Subject: [mg29350] Re: Replacing elements in matrix.
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Thu, 14 Jun 2001 02:27:27 -0400 (EDT)
• References: <9g74fa\$cg6\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Yoram,
Three suggestions:

Mat = Table[1,{5},{5}]

{{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1}}

ReplacePart[Mat,{0},{{2,2},{2,3},{2,4}},{1}]

{{1,1,1,1,1},{1,0,0,0,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1}}

Block[{m=Mat},m[[{2},{2,3,4}]]=0;m]

{{1,1,1,1,1},{1,0,0,0,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1}}

So far the value of Mat has not changed

Mat

{{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1}}

Here we change its value:

Mat[[{2},{2,3,4}]]=0;Mat

{{1,1,1,1,1},{1,0,0,0,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1}}

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Yoram Pollack" <syftech at saad.org.il> wrote in message
news:9g74fa\$cg6\$1 at smc.vnet.net...
> Hello there,
> what will be the best way to replace a few successive elements in one row
in
> a matrix (but not the whole row)?
> For example, in 5x5 matrix, replace elements 2,3,4 of row 2 by {0,0,0}.
> Many thanks
> Yoram
>
>
>

```

• Prev by Date: Re: export & import an expr
• Next by Date: Re: A New User
• Previous by thread: Re: Replacing elements in matrix.
• Next by thread: how to get an assignment from a rule ?