Borrar filtros
Borrar filtros

Using MatLab Workspace user defined objects in Simulink

36 visualizaciones (últimos 30 días)
Alex Ander
Alex Ander el 19 de Mayo de 2022
Respondida: Tushar el 27 de Sept. de 2023
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

Respuestas (1)

Tushar
Tushar el 27 de Sept. de 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!

Categorías

Más información sobre Modeling en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by