Matlab Coder Integration with C #

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

  • Create * .m script in Matlab
  • Make sure the script is compatible with Matlab Coder.
  • Generate C ++ shared library (DLL) using 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();
    }
    
  • In addition, I would like to be able to stop execution and get some partial results. For this, I thought in two ways: StopExecutionandRetrievePartialResults

    [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();
    

Can this be done? If not, are there any alternatives? If so, where can I find more examples?

+4
source share
5 answers

, , MATLAB Builder NE . .Net dll m-.

, MCR .

+3

. MATLAB-, Coder, (, , ).

C C ++/CLR . , P/Invoke, . ++/CLR #, . , , matlab- , .

(- Managed ++, )

bool CTurconConnect2::Init()
{
      // Call the exported function in the library. Imported using a header file. 
      turcon_initialize();
      // Call one of the matlab functions (in this case, the entry function is manually defined 
      // in the C library, to have a clean interface)
      SetParameters(36.0,400.0,20.0,30.0,15.0,40.0,110.0, 0.0, 100.0);
      return true;
}

bool CTurconConnect2::Exit()
{
      turcon_terminate();
      return true;
}
+3

, DLL # .

:

MATLAB #, com. # # MATLAB, .

( ).

MATLAB #

+2

, MATLAB. MATLAB Coder, . , MATLAB, , P/Invoke #, (, ).

:

  • , , " ". / MATLAB . script , .

  • MATLAB , "" "" MATLAB , script. , :

    StartMCL();

    StartScript1_Runtime();

    Run_Script1();

    StopScript1_Runtime();

    StopMCL();

"Script 1 Runtime" MCL, . , , - . , , , MCR 2 "" .

  • / , MATLAB MEX / MATLAB.

, : http://www.mathworks.com/matlabcentral/fileexchange/12987-integrating-matlab-with-c

, . http://www.mathworks.com/help/compiler/shared-libraries.html

+1

,

  • , matlab, , .
  • , , , , ( )
  • matlab - 1 ( , - - )
+1

All Articles