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

  • Home
  • SEARCH
  • 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 9288255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:52:21+00:00 2026-06-18T19:52:21+00:00

I have a c++ program that updates a system. When I wrote everything in

  • 0

I have a c++ program that updates a system. When I wrote everything in C++ it looked a little something like this

System S; //initialize a System object 'S'
while (notFinished)
{
    S.update1(inputVars1);
    S.update2(inputVars2);
}

Now I would like to call the individual update functions from matlab and be able to use access functions (written in c++) to view the state of the program at any time when debugging in matlab.

So matlab will need to call something to instantiate a “System” object, and then it will need to call individual System methods from the original system object.

Suppose I compile separate mex files to Initialize update1 update2 and some that get information about the current state getState. And then write some matlab code…

%matlab main
S = Initalize(); %mex file
while (notFinished)
    update1(S); %mex file
    keyboard; % access state information using "getState" mex function
    update2(S); %mex file
    keyboard; % access state information using "getState" mex function
end

Will this essentially allow me to call and debug my C++ program algorithms in Matlab, or is there another way to go about this whole problem?

  • 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-06-18T19:52:22+00:00Added an answer on June 18, 2026 at 7:52 pm

    The way I would do it is by creating a pointer for System in C++ in the Initialize mex function using “new”. If you are on a 64 bit platform then cast this pointer to a 64-bit integer and create an mxArray with that type and value. Return this mxArray from your Initialize function.

    For later calls to your other mex files you should pass this mxArray as an input. Inside those files you can cast it back as a pointer and call methods on the object.

    I also would take one more step to wrap this whole thing inside a MATLAB System object or a regular object and not expose the pointer value S outside the object. You need methods on the object which would call your mex files. This is especially needed if you are planning to give this to other people for use. Others might accidentally overwrite or modify S causing crashes.

    Finally you need a delete mex function which would delete the pointer S. If you create a handle class then you can do this in the destructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 'server' program that updates many linked lists in shared memory in
I have a Win32 C++ program that validates user input and updates the UI
I have a system that generates particles from sources and updates their positions. Currently,
I have a python program in an embedded system that needs to write to
I have wrote a C# program that has a SQL connection with an entity
so I have this project in java that uses a jni .dll i wrote
I have an update program that is completely independent of my main application. I
I have program that requires Python 3, but I develop Django and it uses
I have program that has a variable that should never change. However, somehow, it
I have program that runs fast enough. I want to see the number of

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.