run mex without argument
    4 views (last 30 days)
  
       Show older comments
    
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.
0 Comments
Accepted Answer
  James Tursa
      
      
 on 17 Jun 2013
        
      Edited: James Tursa
      
      
 on 17 Jun 2013
  
      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 Comments
More Answers (0)
See Also
Categories
				Find more on Introduction to Installation and Licensing in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
