Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to save matrix 2d to array

I have 2 matrix, egnvecx and egnvecy. egnvecx :

[0.52065742, 0.39711261, 0.75578946, 0;
  -0.42713234, 0.88765043, -0.17214788, 0;
  0, 0, 0, 1;
  0.73923874, 0.233192, -0.63178128, 0]

egnvecy :

[1, 0, 0, 0;
  0, 1, 0, 0;
  0, 0, 1, 0;
  0, 0, 0, 1]

Then, I will save this matrix into array it contain x and y. But I dont know how the step is. this the code will be error.

Mat data_pts = Mat(4,4, CV_32F);
    for (int i = 0; i < data_pts.rows; ++i)
    {
        for (int x=0; x<data_pts.cols; x++){
            data_pts.at<float>(i,x) = egnvecx.ptr<float>(i,x);  
            data_pts.at<float>(i,x) = egnvecy.ptr<float>(i,x);  
        }
    }
    cout << data_pts;

thank you :))