1. Create a m-file function which encapsulate your subroutine, and save it to a folder:
2. Add this folder to Matlab path: in Matlab, File > SetPath
3. In MATLAB command window, type “deploytool”
4. In MATLAB window, click the File new icon to create a New Deployment Project.
- In the New Deployment Project dialog box, select MATLAB Builder NE and .NET Component.
- In the name textbox, type whatever meaningful titles, and then click OK.
5. Select “Generate Verbose Output” and Add the source *.m file to the project, and then save the project.
6. Build the component by clicking the “Build “button in the Deployment Tool toolbar. The build process begins, and a log of the build appears in the Output pane of the Deployment Tool. The files that are needed for the component are copied to two newly created subdirectories, src and distrib. A copy of the build log is placed in the src directory. The building process may take quite a few seconds…, have a cup of coffee now…
Now the output folders and files may like this:
7. Now, almost done! Let us try and test it in VisualStudio.net, write source code for a C# application that accesses the component, for instance:
NDimVoronoiDiagram vg=new NDimVoronoiDiagram ( );
MWArray  Results=new MWArray;
Results = (MWArray )vg.CalVoronoiDiagram(2, (MWNumericArray)X, (MWNumericArray)Y);
double [,] VoronoiVertices =(double [,]) Results.ToArray();
object[,] VoronoiEdgeIndice = (object[,])Results.ToArray();
8. Add two references, \toolbox\dotnetbuilder\bin\win64\v2.0\MWArray.dll and the generated dll, in our case, NDimVoronoiDiagram.dll, build the solution, and that is it.
Note that a ” Runtime Error R6034, An application has made an attempt to load … ” occurs one when initializing the NDimVoronoiDiagram object, and I am running Matlab on Vista x64, and I cannot figure out the reason, and if any one has solutions, please let me know.
Extra note I: I put the matlab project inside my VS project folder, and compile it, it results in the failure of reflecting the output dll using ObjectBrowser in VS, and this directly leads to unknown namespace which contains the Matlab class.Very weird.
Extra note II: The namespace, class name and the method name follows the rules as dipicted in the figure below.