Using MatLab Workspace user defined objects in Simulink

조회 수: 13 (최근 30일)
Alex Ander
Alex Ander 2022년 5월 19일
답변: Tushar 2023년 9월 27일
Hello all,
I would like to use an object from a self-defined class in a Simulink simulation.
Until now I have run and monitored my entire simulation through MatLab. First, I created the class object in MatLab and then executed the Simulink simulation steps through a method of the object. I called this method x times according to the simulation conditions. However, each sim command recompiles the model.
Since I use a variable-step solver, I can't use a precompiled model. Therefore I want to change it to a complete Simulink Model which is only compiled once at the beginning of the simulation. Therefore I would like to import the in MatLab initialized object into Simulink and continue calling the object's methods accordingly. So far I have tried importing it in a Matlab function block. However, Simulink does not allow this, as it only allows data of type.
Is it possible to import an existing object from Matlab Workspace into Simulink and modify it with methods.
thank you and greetings
Alex

답변 (1개)

Tushar
Tushar 2023년 9월 27일
Hi Alex,
I understand that you are trying to import an existing object from the MATLAB workspace into Simulink. These are some approaches you can try:
  • Create a MATLAB Function block in the Simulink model.
  • Pass the predefined object from the MATLAB workspace as a parameter. This will allow Simulink to access and modify the object.
  • Call methods of the object using the parameter passed.
  • Connect the MATLAB Function block to other Simulink blocks as needed to construct the system.
Additionally, configure the solver settings in Simulink to match simulation requirements. The Solver Configuration dialog in Simulink can be accessed to choose an appropriate solver type (e.g., ode45, ode23) and set options such as maximum step size and tolerances.
For more information, refer to the below mentioned documentation links:
  1. System Design in Simulink Using System Objects - https://www.mathworks.com/help/simulink/ug/system-design-in-simulink-using-system-objects.html
  2. Modify Model workspace data - https://www.mathworks.com/help/simulink/ug/change-model-workspace-data.html
  3. Specify MATLAB Function Block Properties - https://www.mathworks.com/help/simulink/ug/matlab-function-block-properties.html
Hope this information helps!

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by