Integrating Matlab Coder with c#

19 ビュー (過去 30 日間)
Guilherme
Guilherme 2013 年 10 月 11 日
編集済み: Ryan Livingston 2020 年 3 月 25 日
Hi,
I want to integrate Matlab Coder output with a C# project in Visual Studio. 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();
  1. Is it possible to do?
  2. If no, is there any alternatives?
  3. If yes, where can I find more examples?

採用された回答

Ryan Livingston
Ryan Livingston 2020 年 3 月 24 日
編集済み: Ryan Livingston 2020 年 3 月 25 日
In addition to Bill's answer, generating the interface binding the generated C code to C# with something like SWIG is also an option. Here's an example:
As for starting and stopping the application, there isn't a built-in way for Coder to make a program interruptible. You'll need to design your MATLAB code to support such a behavior by possibly adding StopExecution and RetrievePartialResults entry-point functions which do the right thing when run in your deployed environment.

その他の回答 (1 件)

Bill Chou
Bill Chou 2020 年 3 月 23 日
Yes, it's possible to use MATLAB Coder to integrate with C# applications. One would need to make some manually changes at the interface. Please see this article for more details:

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by