Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how can i introduce this 4 by 4 matrix into that n by n matrix.
Date: Tue, 1 Jan 2013 16:30:09 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 11
Message-ID: <kbv2uh$aa3$1@newscl01ah.mathworks.com>
References: <kbur8s$fnf$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1357057809 10563 172.30.248.48 (1 Jan 2013 16:30:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 1 Jan 2013 16:30:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:785711

"k.vigneshwaran K" wrote in message <kbur8s$fnf$1@newscl01ah.mathworks.com>...
> using for loop i got n by n no of rows and columns of matrix. i have another one specified matrix of 4 by 4.how can i introduce this 4 by 4 matrix into that n by n matrix.
- - - - - - - - -
  Let A be your n x n matrix, let B be a smaller m x m matrix, and you wish to insert the contents of B into A starting at index position (p,q) in A.

 [I,J] = ndgrid(p:p+m-1,q:q+m-1);
 A(I(:)+n*(J(:)-1)) = B;

Of course you have to be sure that p+m-1 and q+m-1 are no greater than n or B wouldn't fit in properly.

Roger Stafford