Is it possible to use the simulink model as a function in matlab?

조회 수: 12 (최근 30일)
Marina
Marina 2024년 7월 11일
댓글: Walter Roberson 2024년 8월 14일
I'd like to call a model I've created on simulink as a matlab function. Is this possible?

답변 (2개)

Andreas Goser
Andreas Goser 2024년 7월 11일
You can run a Simulink simulation in MATLAB using the sim command, do you mean this?

Gayatri
Gayatri 2024년 7월 12일
Hi Marina,
Yes, it is possible to call a Simulink model from within a MATLAB function. Here’s a step-by-step guide on how to do this:
  • The "load_system" function loads the Simulink model into memory.
% Load the Simulink model
modelName = 'my_model';
load_system(modelName);
  • The "sim" function runs the simulation. The output of the simulation is captured in the simOut variable.
% Run the simulation
simOut = sim(modelName);
  • Close the Model: The "close_system" function closes the model without saving any changes.
% Close the model without saving changes
close_system(modelName, 0);
Please refer the below documentations for load_system, sim and close_system:
I hope it helps!
  댓글 수: 1
hanspeter
hanspeter 2024년 8월 14일
With this approach, how do I pass input values into the simulation?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by