Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7049617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:02:28+00:00 2026-05-28T03:02:28+00:00

I want to send a Matrix to Matlab using engine.h in c++ code. The

  • 0

I want to send a Matrix to Matlab using “engine.h” in c++ code. The fact is that I have the data inside a cv::Mat, and I need to sent a mxArray. I tried to use this expression but it doesn´t work:

cv::Mat _priorP;
_priorP = Mat::eye(13, 13, CV_32FC1);
mxArray *mat;
mat = mxCreateDoubleMatrix(13, 13, mxREAL);

memcpy(mxGetPr(mat),_priorP.data, 13*13*sizeof(double));

Anybody knows the correct way to do the conversion? Any help would be apreciated. Thanks.

EDIT

I found this way:
https://stackoverflow.com/a/8848711/744859

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:02:29+00:00Added an answer on May 28, 2026 at 3:02 am

    This thread shows how to convert a CvMat to mxArray. Even though it’s not exactly the conversion code you are looking for, it’s pretty close.

    This is a simple conversion and you should be able to adjust the code to work with cv::Mat instead of CvMat. If you can’t, a quick hack is to convert your cv::Mat data to CvMat and then use the code below as is (taken from the link I suggested):

    mxArray* CvMat_to_new_mxArr (const CvMat* mat)
    {
      const int TYPE = cvGetElemType (mat);
    
      // 2-d image
      if (CV_64FC1 == TYPE) {
        return helper_2dcvmat_to_mat<CV_64FC1> (mat);
      }
      else if (CV_32FC1 == TYPE) {
        return helper_2dcvmat_to_mat<CV_32FC1> (mat);
      }
      else if (CV_32SC1 == TYPE) {
        return helper_2dcvmat_to_mat<CV_32SC1> (mat);
      }
      else if (CV_16SC1 == TYPE) {
        return helper_2dcvmat_to_mat<CV_16SC1> (mat);
      }
      else if (CV_16UC1 == TYPE) {
        return helper_2dcvmat_to_mat<CV_16UC1> (mat);
      }
      else if (CV_8UC1 == TYPE) {
        return helper_2dcvmat_to_mat<CV_8UC1> (mat);
      }
      else if (CV_8SC1 == TYPE) {
        return helper_2dcvmat_to_mat<CV_8SC1> (mat);
      }
    
      //Multi-dimensional arrays not supported, yet.
      /*
      // 3-d image
      else if (CV_64FC3 == TYPE) {
        return helper_rgbimage_to_mat<IPL_DEPTH_64F> (img);
      }
      else if (CV_32FC3 == TYPE) {
        return helper_rgbimage_to_mat<IPL_DEPTH_32F> (img);
      }
      else if (CV_8UC3 == TYPE) {
        return helper_rgbimage_to_mat<IPL_DEPTH_8U> (img);
      }
      */
    
      // unsupported conversion, return null mxArray
      return mxCreateDoubleMatrix(0,0,mxREAL);    
    }
    
    
    template<int TYPE>
    mxArray* helper_2dcvmat_to_mat (const CvMat* mat)
    {
      void* pBeg;
      int pitch;
      cvGetRawData(mat, (uchar**)&pBeg,&pitch);
    
      CvSize size = cvGetSize (mat);
      const mxClassID cid = cvm_traits<TYPE>::CID;
      mxArray* pArrOut =
      mxCreateNumericMatrix(size.height,size.width,cid,mxREAL);
      void* pBegOut = mxGetData(pArrOut);
    
      typedef mc_traits<cid>::CT T;
      pix_iterator_2d<T,eRowWise> it_src1(static_cast<T*>(pBeg),
      size.width,size.height,pitch);
      pix_iterator_2d<T,eRowWise> it_src2(static_cast<T*>(pBeg),
      size.width,size.height,pitch);
      it_src2.end ();
      pix_iterator_2d<T,eColWise> it_dest(static_cast<T*>(pBegOut),
      size.width,size.height);
    
      std::copy (it_src1,it_src2,it_dest);
    
      return pArrOut;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code that proceses frames in each iteration and generatesa matrix. My
I want to send a URI as the value of a query/matrix parameter. Before
I want so send every week an update by email. But Im afraid that
I want send some data to a remote webpage from my site. Actually it
I have found this little script in PHP that send a simple request to
I have flv files that contain audio tags with a aac raw data. Each
I want to send a UIImage to a server with socket. I'm using this
I want to send out an NSArray, so I have to write it to
I want to send the data of a UIImage to the server through a
My data is an xml element & I want send PUT request with JavaScript.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.