       Re: Setting parts of matrices

• To: mathgroup at smc.vnet.net
• Subject: [mg2966] Re: Setting parts of matrices
• From: espen.haslund at fys.uio.no (Espen Haslund)
• Date: Wed, 17 Jan 1996 03:09:18 -0500

```In article <4cqk0q\$ig5 at dragonfly.wri.com>, jnygaard at math.uio.no says...
>
>Can somebody tell me how to set a submatrix of a larger matrix?
>Assume a is a larger matrix than b. I would like to do something
>like
>
>  a[[Range[i1,i2],Range[j1,j2]]]=b;
>
>Unfortunately, this does not work, and the Mathematica-book of
>Wolfram doesn't tell me how to do it. It just says that
>
>  a[[Range...
>
>is the way to *extract* things from a matrix.
>
>
>Jens Olav Nygaard
>
>
Hei, Jens,

It appears that no elegant solutions are posted for your problem,
so here is an un-elegant one:

replaceMatrixPart[a_,i1_,j1_,b_] :=
Module[{i2, j2, aa},
aa = a;
{i2, j2} = {i1, j1} + Dimensions[b] - 1;
Do[aa[[i, j]] = b[[i-i1+1, j-j1+1]], {i,i1,i2}, {j,j1,j2}];
aa
]

This replaces part of the matrix a [from (i1, j1) to the extent of b]
with the elements of the matrix b,
(note that the original matrix a is kept intact)

This Function is NOT tested for robustness or correctness!

-Espen

==== [MESSAGE SEPARATOR] ====

```

• Prev by Date: Re: Re: Re : Moebius strip
• Next by Date: Re: Setting parts of matrices
• Previous by thread: Setting parts of matrices
• Next by thread: Re: Setting parts of matrices