Clear Filters
Clear Filters

Using MatLab Workspace user defined objects in Simulink

36 views (last 30 days)
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

Answers (1)

Tushar
Tushar on 27 Sep 2023
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!

Categories

Find more on Modeling in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!