Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how can i introduce this 4 by 4 matrix into that n by n matrix.

Subject: how can i introduce this 4 by 4 matrix into that n by n matrix.

From: k.vigneshwaran K

Date: 1 Jan, 2013 14:19:08

Message: 1 of 3

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.


i used
for i=1:1:n

end

example:
if i==3
  in that particular point i want to control my loop.





i tried like

 
for i=1:1:n

if i==3

end
end



end

Subject: how can i introduce this 4 by 4 matrix into that n by n matrix.

From: dpb

Date: 1 Jan, 2013 15:56:03

Message: 2 of 3

On 1/1/2013 8:19 AM, k.vigneshwaran K wrote:
> 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.
>
> i used
> for i=1:1:n
...

> example:
> if i==3 in that particular point i want to control my loop.
>
...

Not at all clear what you really want, but in general one can do most
things in ML w/o explicit loops...taking a wild guess, try the following
at command line--

I=eye(4); % a 4x4 matrix example
M=rand(10,4); % another that is 10x6
M(3:6,:)=I % put I in M at row 3

That give you any ideas on your problem????

--

Subject: how can i introduce this 4 by 4 matrix into that n by n matrix.

From: Roger Stafford

Date: 1 Jan, 2013 16:30:09

Message: 3 of 3

"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

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us