Thread: Running C++ Code from Matlab GUI

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    1

    Running C++ Code from Matlab GUI

    Hi there, this is my first post. I have a question in regards to running a C++ program from a Matlab GUI. I have spent hours looking through information online and I understand the method that is described is using MEX files. However, all of the tutorials and example I have found, including on the Mathworks site, are for relatively short C++ functions.

    So, my question is: how do I get Matlab to run a large C++ program? It has about 20 cpp files which call upon each other to run the program. There is one Main function which then runs the entire program but I don't believe its enough just converting the main function, correct me if I'm wrong. Must I copy all of those files into Matlab and turn them all into MEX functions? That doesn't sound efficient to me but I am a novice in this field.

    My professor said that there used to be a Matlab GUI in the lab that was capable of doing this so it should be possible. I have been tasked with recreating it and would appreciate any assistance.
    Last edited by cpp_novice; 06-16-2011 at 06:15 AM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If those 20 files make just one program, and you just need the output from Matlab, I suspect that you can just MEX the main() and go. (I don't know enough about the interface to know whether you need all the functions in the file, or whether you can turn the other 19 into a .dll or something similar to call, or what exactly.) If you have a bunch of functions that you will need to call from Matlab independently of each other, then I think the library approach might work better (you can turn any number of code files into a single .dll).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. glue C and matlab code
    By shaoshao in forum C Programming
    Replies: 1
    Last Post: 06-10-2011, 09:13 AM
  2. Why my code will stop running? Thanks!
    By ljin in forum C Programming
    Replies: 7
    Last Post: 08-25-2009, 01:41 AM
  3. Running Exe in C++ Code.
    By Ti22 in forum C++ Programming
    Replies: 5
    Last Post: 03-23-2006, 01:29 PM
  4. running executables in c code
    By cathal in forum C Programming
    Replies: 2
    Last Post: 08-20-2004, 05:29 AM
  5. running code EXACTLY once
    By Trauts in forum C++ Programming
    Replies: 12
    Last Post: 07-11-2003, 12:24 PM