Can you please help me deploy simulink functions for.Net Assembly?

3 views (last 30 days)
Hi Team
Our aim is to create a Simulink model using a MATLAB script and then convert it to .Net assembly with the aid of the Matlab compiler SDK and Simulink compiler. But We encountered an undeployable error when executing the following functions:
new_system, load_system, open_system, save_system, add_block, add_line, close_system, Simulink. Mdlinfo.
Can you please help us deploy these functions for.Net Assembly?

Answers (1)

Hitesh
Hitesh on 27 Jan 2025
Hi Rajesh,
Simulink models and certain Simulink functions are not directly supported for deployment through MATLAB Compiler SDK. However, you need to work around this by using MATLAB scripts to perform operations on Simulink models before deployment and then using MATLAB functions that can be compiled.
Kindly follow the following steps to deploy the Simulink functions for .Net Assembly:
  • Script : Write a basic script that creates a Simulink model and performs some operations including functions new_system, open_system, save_system, add_block, add_line, close_system.
% Create a new Simulink model
modelName = 'myModel';
new_system(modelName);
open_system(modelName);
% Add blocks and lines
add_block('built-in/Constant', [modelName, '/Constant']);
add_block('built-in/Scope', [modelName, '/Scope']);
add_line(modelName, 'Constant/1', 'Scope/1');
% Save the model
save_system(modelName);
% Close the system
close_system(modelName);
  • Wrap Model Operations in a MATLAB Function: Create a MATLAB function that can be compiled. This function will not directly manipulate the Simulink model but will instead perform operations that can be compiled.
function result = runSimulinkOperations()
% Call the script that manipulates the Simulink model
mySimulinkScript();
% Return some results or status
result = 'Simulink operations completed successfully';
end
  • Compile the MATLAB Function: Use the MATLAB Compiler to compile the MATLAB function into a .NET assembly.It would generate directive named "output" which will contain all the necessary files.
mcc -W 'dotnet:MySimulinkAssembly,Class1,0.0,private' -T link:lib -d output runSimulinkOperations.m
  • Deploy the .NET Assembly: The compiled .NET assembly can now be used in a .NET environment. Ensure that the MATLAB Runtime is installed on the target machine where the .NET assembly will be used.

Categories

Find more on MATLAB Compiler SDK in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!