MATLAB Answers

0

Superimposing matrices in a specific location

Asked by Allie Feinberg on 17 Oct 2019
Latest activity Edited by Matt J
on 18 Oct 2019 at 22:42
I have two matrices, one 1024x1024 and one 101x101. 95% of the matrices consists of zeros, besides the central circular parts which have values ranging between 0 and 1. When displayed, the matrices show a circle.
I want to superimpose the smaller matrix onto the larger matrix in a specific location from the origin of the larger matrix. How can I extract the values from the smaller matrix and superimpose them onto the larger matrix?
Thanks

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Matt J
on 18 Oct 2019
Edited by Matt J
on 18 Oct 2019
 Accepted Answer

Something like this, perhaps:
[i0,j0]=deal(700,850); %target location
[I,J,S]=find(smallMatrix);
result = largeMatrix + accumarray([I-51+i0,J-51+j0], S ,[1024,1024]);

  2 Comments

Thanks so much, this worked!
Matt J
on 18 Oct 2019 at 21:38
Glad to hear it, but please Accept-click the answer to indicate this!

Sign in to comment.