Multiply the sub-matrix by a constant

Let's say I have a matrix

a =  [ 1 1 1 1;
       1 1 1 1;
       1 1 1 1]

And I would like to multiply the submatrix a(2:3, 2:3)by 5; So the new matrix

a =  [ 1 1 1 1;
       1 5 5 1;
       1 5 5 1]

Which function does this? I tried this =>

a = a(2:3, 2:3)*5;

But it just gives me a new 2x2 matrix

a = [5 5;
     5 5]
+4
source share
1 answer

You need to specify the target correctly.

A=ones(6,6);
A(3:4,3:4) = A(3:4,3:4)*5

A =
 1     1     1     1     1     1
 1     1     1     1     1     1
 1     1     5     5     1     1
 1     1     5     5     1     1
 1     1     1     1     1     1
 1     1     1     1     1     1
+8
source

Source: https://habr.com/ru/post/1623087/


All Articles