Using MatLab Workspace user defined objects in Simulink

11 次查看(过去 30 天)
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