Help on matrix multiplication

asked 2015-07-09 09:58:50 -0600

Nbb gravatar image

updated 2015-07-09 09:59:10 -0600

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 flag offensive close merge delete

Comments

which error(s) ?

berak gravatar imageberak ( 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)
Eduardo gravatar imageEduardo ( 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
berak gravatar imageberak ( 2015-07-09 11:40:22 -0600 )edit