How to multiply a matrix by a scalar values in MatLab? for example X = [234 75 98 39; 91 186 101 116; 149 136 39 119; 95 175 126 39]. Multiply each row by a different scalar e.g 2, 3, 6, 4 respectively.
This involves concepts of simple matrix multiplication, which is:
If we multiply a diagonal matrix with another matrix A, then the matrix A each row is multiplied by the element present in that row of the diagonal matrix. (Take some example and solve it yourself to observe the explanation.)
Here is the MATLAB code:
X = [234 75 98 39; 91 186 101 116; 149 136 39 119; 95 175 126 39]
Y = diag([2 3 6 4])*X % output -> diagonal matrix is created by the required scalars and multiplied by X
Output:
Y =
468 150 196 78
273 558 303 348
894 816 234 714
380 700 504 156
Get Answers For Free
Most questions answered within 1 hours.