Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1996

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

Search the Archive

Re: Replacing part of a matrix by another

  • To: mathgroup at
  • Subject: [mg5621] Re: Replacing part of a matrix by another
  • From: killough at
  • Date: Sun, 29 Dec 1996 00:56:24 -0500
  • Organization: Convex Technology Center of Hewlett Packard, Richardson, Tx USA
  • Sender: owner-wri-mathgroup at

In article <59voui$f82 at>,
Lidar (Hamburger) dani <dani at> wrote:
>Given a matrix M and a smaller matrix L, what is an elegant way to replace a
>submatrix of M by L, at some specified position {p,q}?
>For example:
>M = Array[m,{5,5}]
>L = Array[l,{2,2}]
>L should replace {{m[2,3],m[2,4]},{m[3,3],m[3,4]}}.


setsub[M_,L_,pos_] := Array[ ( M[[##2]] = L[[Sequence @@ #]] )&
                             [ {##}, Sequence @@ ({##}+pos-1) ] &,
                             Dimensions[L] ]

Then setsub[M,L,{p,q}] should produce the desired results.

You're welcome in advance

  • Prev by Date: Re: Weibull Distribution
  • Previous by thread: Replacing part of a matrix by another
  • Next by thread: 2d interpolation with irregularly spaced data