Here is a sample for deploying Simulink model to .NET dll using MATLAB Compiler SDK & Simulink Compiler.
First, create MATLAB function which uses Simulink.SimulationInput and sim commands.
deployParameterTuning.m
function [t, data] = deployParameterTuning(mb)
if ischar(mb) || isstring(mb)
if isnan(mb) || ~isa(mb, 'double') || ~isscalar(mb)
disp('The value of mb given to deployParameterTuning must be a double scalar or a string or character that can be converted to a double scalar');
in = Simulink.SimulationInput('sldemo_suspn_3dof');
in = in.setVariable('Mb', mb);
in = simulink.compiler.configureForDeployment(in);
t = out.logsout{1}.Values.Time;
data = out.logsout{1}.Values.Data;
Then, compile the m script as .NET Assembly using Library Compiler. Click "Package".
You will get a .NET dll file in deployParameterTuning\for_redistribution_files_only.
In Visual Studio, create C# console application.
In this case, solution name is dotNetSlTest.sln and add two references. First is MWArray.dll from (MATLAB_INSTALL\toolbox\dotnetbuilder\bin\win64\v4.0) and the second is deployParameterTuning.dll you just compiled from above .m code.
Then, write the following C# code.
Program.cs
using deployParameterTuning;
using MathWorks.MATLAB.NET.Arrays;
static void Main(string[] args)
MWNumericArray data = null;
// Because class instantiation and method invocation make their exceptions at run time,
// you should enclose your code in a try-catch block to handle errors.
// Instantiate your component class.
result = obj.deployParameterTuning(2, args[0]);
// Extract the Magic Square you created from the first index of result
t = (MWNumericArray)result[0];
data = (MWNumericArray)result[1];
In Visual Studio, change the target CPU to x64 from Any CPU, then build the solution.
Once you obtain the .NET exe file, run the following.
For applying this approach to you actual Simulink model and MATLAB codes, please check this document whether the MATLAB functions, Simulink blocks and Toolbox which you're using are supported in MATLAB Compiler / Simulink Compiler.