Unable to execute sim command for simulation from C# .Net

Hi, I want to pass model name from c# code to Matlab method which simulates that model and returns results. I have used MWCharArray to store model name and passed it to matlab method. I am getting exception as "Undefined function or method 'sim' for input arguments of type 'char'".

Answers (2)

5 Comments

Oh!!!
Scenario is like this:
User specifies model name and necessary variables on User interface built by c#. C# method uses DLL built by Matlab .Net builder. This DLL has methods for simulation. So i want to pass model name to that method for simulation. Is it not possible??
Unfortunately this is not possible.
You will need to compile the model using Simulink Coder (previously named Real-Time Workshop). The generated executable you can call from C# (or compiled MATLAB code).
Alternatively, if your .NET application is running on a computer that has MATLAB installed, you can start MATLAB as a COM server to run the SIM command: http://www.mathworks.com/help/techdoc/matlab_external/brd0v3w.html
Hi Kaustubha,
Could you please give me more details on how to start Matlab as COM server????
I dont want to use C# DLL in Matlab but I want to use Sim command in C#.

Sign in to comment.

Hi,
I created an example and uploaded the C# project here
(is there any way to share files here?)
You have to modify the reference to your ML which you are using. Otherwise it won't run.

3 Comments

Thnx Friedrich. You have been so helpful. Well, If i follw the approach that you have given in sample application, Matlab software has to be installed on the machine. Earlier i did the same thing but requirement is like I should use only MCR. So I cant use MLApp COM.
Unfortunately there is no way around. When you like to use the ML automation server you need a MATLAB installed. The MCR won’t work here.
If your application should run on a PC without ML installed the only way is to use Simulink Coder (previously Real-Time Workshop) to generate code or an executable from your Simulink model which you can call from C#.
Using installed ML you can use the sim command.
On a PC without ML you have to “compile” your Simulink model first. Good point here is, no MCR is needed at all because you generate plain c or C++ code:
http://www.mathworks.com/products/simulink-coder/index.html
I have deployed simulink.m into exe. I will start this exe from my C# code. Now I want to send model name as parameter to this exe and get results of simulation. How can I do this?

Sign in to comment.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Asked:

on 13 Jul 2011

Community Treasure Hunt

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

Start Hunting!