How can I multiply 3 matrices?

asked 2014-02-21 20:54:37 -0600

Nihad gravatar image

I would like to multiply 3 matrices(same size). For eample, NM=(-0.5)HSH where H,S are matrices having same size. Here is my code, but it produces nan output. How can i multiply 3 matrices?

int main()
int count_row=1000;
 vector <vector <float> >g;
//do some calculation on g

Mat M(count_row,count_row,CV_32F);
for(int i=0;i<count_row;i++)
     for(int j=0;j<count_row;j++)


Mat I = Mat::eye(count_row, count_row, CV_32F);

Mat H(count_row,count_row,CV_32F);

Mat S(count_row,count_row,CV_32F);

Mat normalized_M(count_row,count_row,CV_32F);

cout<<normalized_M<<endl;// error: produce nan output
edit retag flag offensive close merge delete


Put an isnan(g[i][j]) check in your for loop.

Nghia gravatar imageNghia ( 2014-02-22 07:36:26 -0600 )edit

you can also make use of overloading of operators as done in c++ programming by creating an overloaded * operator function.

Abhishek Kumar Annamraju gravatar imageAbhishek Kumar Annamraju ( 2014-02-26 02:34:08 -0600 )edit