5

I have an algorithm implemented in Matlab and I'm planning to deploy it as a DLL for integration with a .NET project. The .NET project is a GUI based application a small part of which consists of displaying the results obtained from running the algorithm. The problem I currently have is that I need to display intermediary results. The algorithm is quite intricate and runs for a number of iterations (chosen by the user) and at the end of each iteration the GUI should be updated with the current data.

The best solution that I have in mind at the moment is for the Matlab thread to act as a tcp client to the local tcp server that I would start in my C# GUI app. However, I feel this approach is inefficient. I was wondering whether this could be achieved some other way.

Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104
filipcampeanu
  • 159
  • 1
  • 9

1 Answers1

5

First of all, judging by your question, I guess you know about Matlab builder NE. It allows you to deploy a .NET DLL. If you don't know, try it.

Regarding your options:

1) You can pass a .NET object to your Matlab code that will serve as a communications means. Create a new instance of this class, and send to your Matlab code as input. The Matlab code will call the UpdateGui logic with each iteraion. The following example is in C#

 class GuiUpdater{
      public void UpdateGui(int param1,int param2){
           //Do update logic here.
      }
 } 

2) Compile your DLL as COM (It is also possible in Matlab Builder NE), and use COM communication.
3) Use the filesystem as communication means. Write to a file in Matlab, and read it in .NET.

Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104
  • Thanks for the answer. However, wouldn't using solution 1 mean that the GuiUpdater would have to have visibility to the whole GUI code? Wouldn't this in turn mean that the whole C# project would be bundled in the DLL? – filipcampeanu Jan 12 '12 at 15:58
  • @filipcampeanu, Yes, the GuiUpdater would have to have access to the whole GUI. I don't understand your second question, please explain. – Andrey Rubshtein Jan 12 '12 at 16:12
  • Sorry, I was being confusing. The solution seems nice but I can't integrate it with my project. I was thinking about the alternative of wrapping a Matlab object around the algorithm code, deploying it as a DLL, instantiating it in C# and calling methods on that object from C#. I am not sure, however that one can do this. For example I've tried instantiating a class with MWArray[] result = matlab.MyClass(1, input), but by the end of the call result contains one null element (which should in fact have been the reference to the instantiated object). I am wondering whether this is possible. – filipcampeanu Jan 12 '12 at 19:19