how to perform simulation in matlab from c++ code

6 views (last 30 days)
I am writing a code for A* algorithm for path planning in c++. My question is how can i use this code in Matlab, or call from Matlab because later I want to perform the simulation in Matlab. I have read about the c-mex and currently working on it. just the matter of fact i/m still vague about the process of writing the c-mex file. Another thing is I've came across something called as S-function. I know that this function is used in simulink to perform the simulation and how actually all these things relate.
What is on my mind to carry on the project is like this: 1. first after i created the c++ code i need to modify the main() into mex gateway. 2. then i compiled the mex file and call it from matlab command. 3. then i need to do the simulation. how to perform the simulation? is it using s-function or is there other way to do that?
sorry, english isn't my primary language and i have some difficulties in deciphering english text especially the technical one.
thank you in advanced.

Accepted Answer

Kaustubha Govind
Kaustubha Govind on 17 Jul 2013
If you plan to simulate only in MATLAB, a MEX-function is sufficient. C-MEX S-functions are a special category of MEX-files that can only be executed by the Simulink engine, and allow additional abilities like discrete/continuous states, etc. If you don't need to use any of the more advanced S-function features, I'd recommend that you simply create a MEX-file for your C/C++ code that you can execute in MATLAB like any other function, and can also call from Simulink using an Interpreted MATLAB Function block.
  2 Comments
khairul ismail
khairul ismail on 18 Jul 2013
from documetation it said: The binary MEX-file name, and hence the name of the function you use in MATLAB, is the name of the source file containing your gateway routine.
i am a bit confused here: what if my source file(one file) consists more that one classes and a mexFunction together,what should i name my source file? and how can i call my program from matlab because my program will start from main() in c++ or equivalent to mexFunction in cmex file?
tq
Kaustubha Govind
Kaustubha Govind on 18 Jul 2013
You should not have your main() in the MEX-file, but mexFunction (and possibly other classes or functions). Whichever file contains the mexFunction entry-point is treated as the main file in MATLAB, regardless of whether you have additional code in it.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!