# Help on matrix multiplication

Hi forum, Im trying to perform a matrix multiplication + addition but I am getting an error. Below are the 3 variables

Mat MatrixB = (Mat_<float>(5, 5) << 1, 0, 1, 0, 0,
0, 1, 0, 1, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0,
0, 0, 0, 0, 1);


Mat noise(5, 1, CV_32F, 0);

for (int i = 0; i < 200; i++) MatrixA.push_back(Mat::zeros(5, 1, CV_32F));

Noise and MatrixA gets initialized to some value. However when I do the following operation MatrixA = MatrixB * MatrixA + noise I get an error.

edit retag close merge delete

which error(s) ?

( 2015-07-09 10:26:44 -0600 )edit
2

For me there is a problem with the dimension of the matrices. What is the size of MatrixA (it should be 5x1) ?

(1000x1) = (5x5) * (1000x1) + (5x1)

( 2015-07-09 11:35:00 -0600 )edit
1

@HasiqBR, i think, you wanted:

for (int i = 0; i < 200; i++) MatrixA.push_back(Mat::zeros(1, 5, CV_32F));


(a [5x200] Mat, not a [1x1000] one) .

and then, it should be

MatrixA = MatrixA * MatrixB + noise

( 2015-07-09 11:40:22 -0600 )edit