C# call the Matlab function to compute the nonlinear programming problem?
Show older comments
I just know how to solve a linear programming,but I didn't know how to abou a nonlinear programming. How can I call the Matlab function in the WinForms to solve a nonlinear programming? That means C# pass the required data to Matlab function ,and I didn't know how to pass parameters between C# and Matlab as to solve anonlinear programming. Would anyone give me some examples? Thanks a lot!
Answers (1)
Kaustubha Govind
on 29 Mar 2011
0 votes
One option is to start MATLAB up as a COM server from your C# application. The example Calling MATLAB Software from a C# Client describes how you can pass data in and out of MATLAB.
4 Comments
James Bai
on 31 Mar 2011
Kaustubha Govind
on 31 Mar 2011
You can create a MATLAB script/function to solve the equation (I would recommend first testing your function with some sample data before you try invoking it from .NET). Once you have that ready, you can follow the "Calling MATLAB Software from a C# Client" example to pass in variables required by your function. Additionally, you would use matlab.execute("command to run your script") to run your file.
James Bai
on 1 Apr 2011
Kaustubha Govind
on 1 Apr 2011
I don't have much experience with non-linear programming - please create another question for that part, so someone else can help you with it. To disable all warnings, you can use "warning off" at the start of your function - i would recommend using "warning on" at the end of the function, to restore the original warning state. You should make your code error-free to be able to successfully obtain results in C#.
Regarding passing data - again, you can simply use PutFullMatrix and GetFullMatrix as described in the cited example. Another alternative that I didn't mention before is MATLAB Builder NE (http://www.mathworks.com/products/netbuilder/), but you may not need it unless you want to run your C# application that does not have MATLAB installed.
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!