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 7052035
In Process

The Archive Base Latest Questions

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

I have a code that proceses frames in each iteration and generatesa matrix. My

  • 0

I have a code that proceses frames in each iteration and generatesa matrix. My final goal is to send the matrix data to matlab in order to examine the evolution of the matrix with each frame.
In order to achieve this I defined a static variable Engine in a header file (helper.h).

#include "engine.h";
#include "mex.h";
static Engine *engine;

In the main() program I open the engine only once:

#include helper.h   


main(){
if (!(engine = engOpen(NULL))) {
    MessageBox ((HWND)NULL, (LPSTR)"Can't start MATLAB engine",(LPSTR) "pcTest.cpp", MB_OK);
    exit(-1);}

//here comes frame processing using a while loop
.
.  //a function is called (defined in matrix.cpp)
.
//frame processing ends
}

And inside matrix.cpp is where I get the matrix I want to send to Matlab Engine, so I do something like this:

#include helper.h

mxArray *mat;   
mat = mxCreateDoubleMatrix(13, 13, mxREAL);     
memcpy(mxGetPr(mat),matrix.data, 13*13*sizeof(double));
engPutVariable(engine, "mat", mat);

I want to use the pointer to engine the most efficient way. I am a bit conffused about how to correctly use matlab engine.

Any help woould be welcomed, because the matlab documentation and examples didn’t help at all as they have all the code in the same file and they don’t use iterations. Thanks in advance.

EDIT

First problem solved about the engine pointer. The solution is declaring it as extern.

#include "engine.h";
#include "mex.h";
extern Engine *engine;

and in main.cpp

#include helper.h   
Engine *engine=NULL;

main(){}
  • 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:20:08+00:00Added an answer on May 28, 2026 at 3:20 am

    static means “local to the current compilation unit”. A compilation unit is normally a single .cpp file, so you have two engine variables in your program, one in main.o and one in matrix.o. You need to declare engine as extern in the header file and define it without any modificator in exactly one .cpp file.

    helper.h:

    extern Engine* engine;
    

    main.cpp:

    #include "helper.h"
    Engine* engine = NULL;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that looks like: //System.Data.IDataRecord dr try { Consolidated = Utility.NullConvert.ToBool(dr[Constants.Data.Columns.cConsolidated], false);
I have some code that starts a background process for search in my WPF
I have a process that contains C# code, C++\CLI code and native c++ code.
I have code that references a web service, and I'd like the address of
I have code that looks like the following, which works fine for displaying the
I have code that looks like this: template<class T> class list { public: class
I have code that I want to look like this: List<Type> Os; ... foreach
I have code that uses Win API function RegSaveKeyEx to save registry entries to
I have code that uses jquery.slideup and jquery.slidedown How can i know that div
I have code that calls an ENTRY in a SUBROUTINE before the SUBROUTINE .

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.