run mex without argument

11 次查看(过去 30 天)
Hello, I am creating a c++ code for A* algorithm. I want to run it in the matlab because later i want to perform the simulation. I have created the mexfunction. I want to know how i can call the main(replaced by the mexfunction) from matlab command without passing the argument because i don't think(for the time being because so far this is all i can think) i need to pass any parameter to call the mexfunction. Some of the data i already define as constant inside the c++ code?
I am just moving to matlab and any misconceptions please clarify. Thank you in advance.

采纳的回答

James Tursa
James Tursa 2013-6-17
编辑:James Tursa 2013-6-17
If you are not passing in any arguments or passing out any results, it is pretty simple. Just replace the "main" line with the "mexFunction" line as you have apparently already done. Suppose the filename is myfunction.cpp, then take these steps:
1) Put myfunction.cpp in a directory that is on the MATLAB path.
2) Make that directory your current directory.
3) Issue the following command at the command line prompt:
> mex myfunction.cpp
That will create the mex function for you. Now you can invoke it just like any other function. During compilation if you get a question about searching for compilers, answer Yes, press Enter, then select the number of the C++ compiler that you have installed and will be using. Note that MATLAB does not come with a C++ compiler, you have to get that and install it yourself separately.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by