Search code examples
c#matlabdllmatlab-deploymentmatlab-coder

Integrating Matlab Coder with c#


I want to integrate MATLAB Coder output with a C# project in Visual Studio 2010. My main idea is:

  • Create a *.m script in Matlab
  • Make sure the script is compatible with Matlab Coder.
  • Generate a C++ shared library (DLL) with Matlab Coder
  • Integrate with C# using something like this:

    //Starts the model execution. May take several minutes
    public static class DllHelper
    {
        [DllImport(@"test.dll",CallingConvention=CallingConvention.Cdecl,EntryPoint = "Run()")]
        public static extern int Run();
    }
    
  • Also, I would like to be able to stop the execution and retrieve some partial results. To do this, I was thinking in two methods: StopExecution and RetrievePartialResults

    [DllImport(@"test.dll",CallingConvention=CallingConvention.Cdecl,EntryPoint =     "StopExecution ()")]
    public static extern int StopExecution ();
    
    [DllImport(@"test.dll",CallingConvention=CallingConvention.Cdecl,EntryPoint = "RetrievePartialResults()")]
    public static extern MyResults RetrievePartialResults();
    

Is it possible to do? If no, is there any alternatives? If yes, where can I find more examples?


Solution

  • I have no idea if your plan works, but MATLAB Builder NE might be an alternative. It directly outputs a .Net dll without those hard limitations to the m-code.

    The disadvantage is, that MCR is required on the target machine.