Reputation: 16
I am building a Windows Forms Application that uses a MATLAB back end. What is the best, possibly cleanest, way to do this? Furthermore, I need to grab the MATLAB output data and work with it in the Windows Forms program.
What I have done so far:
Using the Process class I ran a batch file that calls the MATLAB program:
Process process = new Process();
process.StartInfo.FileName = @"----\run.bat";
process.StartInfo.WorkingDirectory = @"----";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
I am able to run the script without a problem. However, I cannot receive the output stream from MATLAB. I tried all of the solutions in the link above, but it does not work in my particular situation. I assume this has something to do with MATLAB.
Upvotes: 0
Views: 3487
Reputation: 371
The best way is probably to use the COM interface supplied by Matlab.
You'll need to add a reference to your C# project referencing the Matlab Application, then instantiate an object of type MLApp, which will allow you to call Matlab. For a simple example refer to http://www.mathworks.com/help/matlab/matlab_external/call-matlab-function-from-a-c-client.html.
Upvotes: 2