2

I am building an application which needs high response time in a real time environment. I know there are three methods to call MATLAB from C#:

  1. MATLAB Engine using COM automation
  2. .NET Assembly created in MATLAB using Builder for .NET
  3. C Shared library created in MATLAB using Compiler

What are the differences between these methods in terms of speed (execution time)? Any comments about the relative security of the methods would also be appreciated.

Thanks

Sam Roberts
  • 23,951
  • 1
  • 40
  • 64
Seemal Asif
  • 29
  • 1
  • 3

1 Answers1

2

Here is some hint for your question

COM approach This solution is quite slow because of the COM type exchange

Dynamic Data Exchange The Dynamic Data Exchange is a quite old but powerful service of Windows that lets applications communicate and exchange data

C API The direct access to the MATLAB C API is the best solution in terms of performance and features, just let use P/Invoke and some unsafe pointer operations.

You may read more http://www.codeproject.com/Articles/5468/1-2-3-ways-of-integrating-MATLAB-with-the-NET

hope it will helpful.

Rajeev Bera
  • 2,021
  • 1
  • 16
  • 30
  • Thanks for reply. I have already read the article mentioned. It does explain very well each method and its usage. What about if we need to use Matlab compiler which is building an assembly for .Net which can be directly referenced from code? and what about the third method I mentioned? – Seemal Asif Jun 12 '13 at 13:16
  • its mentioned here http://stackoverflow.com/questions/5901664/calling-a-matlab-function-from-c-sharp – Rajeev Bera Jun 12 '13 at 13:24
  • "MATLAB C API is the best solution..." Do you have any facts to support this? – James Mertz Jun 12 '13 at 14:05
  • nice find but the CodeProject article is a bit outdated. [DDE support](http://undocumentedmatlab.com/blog/matlab-dde-support/) is deprecated (and no longer documented). The use of the COM interface is overly complicated (use the TypeLibrary Import mechanism instead of manually messing with IDispatch). Finally using P/Invoke to call the Engine API is not much faster since the [Engine API](http://www.mathworks.com/help/matlab/matlab_external/supported-client-server-configurations.html#bq9yam7-10) is also based on COM in Windows, so I think you will get comparable speeds – Amro Jun 12 '13 at 14:37
  • @SeemalAsif: I think the "Builder NE" approach is currently the recommended method (generating a .NET assembly using the Compiler toolbox). The advantage is that the result only depends on the MCR (no need to have MATLAB installed on the target machine) – Amro Jun 12 '13 at 14:46