how to perform simulation in matlab from c++ code
6 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
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
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.
More Answers (0)
See Also
Categories
Find more on Use Prebuilt MATLAB Interface to C++ Library in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!