insert a small matrix inside a big matrix

i have a 1000 x 1000 matrix and a 45 x 45 matrix. both have random numbers. how can i insert the small matrix in the bigger one at a given location. lets say i want to insert the small matrix from 250 x 250 onwards. How do i do it ? I do not want the elements of the big matrix to become zero for all other places left after inserting the smaller matrix, i mean padding the small matrix with zeros wont be helpful in this case. Please assist.

回答 (1 件)

Todd Leonhardt
Todd Leonhardt 2016 年 5 月 25 日

3 投票

You do it like so. Suppose your 1000 x 1000 matrix is called big and your 45x45 matrix is called little.
big(250:294, 250:294) = little;

6 件のコメント

Walter Roberson
Walter Roberson 2016 年 5 月 25 日
More generally:
startrow = 250;
startcol = 250;
endrow = startrow + size(little,1) - 1;
endcol = startcol + size(little,2) - 1;
big(startrow : endrow, startcol : endcol) = little;
Anvinder  Singh
Anvinder Singh 2016 年 5 月 25 日
Thanks Todd, this is exactly how i did but it gives an error : " Subscripted assignment dimension mismatch. "
Anvinder  Singh
Anvinder Singh 2016 年 5 月 25 日
Thanks walter. I realize my mistake. Your code works.
Matt J
Matt J 2016 年 5 月 25 日
Since it works, you should Accept-click Todd's answer.
Alyssa Martinez
Alyssa Martinez 2019 年 2 月 20 日
How did you get 250:294 in there?
oliver murray
oliver murray 2020 年 11 月 4 日
250 to 294 is 45 places

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2016 年 5 月 25 日

コメント済み:

2020 年 11 月 4 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by