How do I access base workspace variables from a MATLAB Function Block?
89 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 22 de Jul. de 2019
Editada: MathWorks Support Team
el 15 de Jun. de 2023
How do I access base workspace variables from a MATLAB Function Block?
Respuesta aceptada
MathWorks Support Team
el 15 de Jun. de 2023
Editada: MathWorks Support Team
el 15 de Jun. de 2023
Due to the differences in how the code within a MATLAB function block interacts with the Simulink solvers, some additional steps must be taken to access base workspace variables from the MATLAB function block. There are a number of options to do so:
1) Use Data Store Memory to import Simulink.Signal objects. By specifying a variable of type Simulink.Signal's scope as 'Data Store Memory' within the MATLAB function block "Ports and Data Manager", you may access the variable from the base workspace.
See the following documentation section for an example of how to do so for a variable in the model workspace. The workflow is identical to reference variables in the base workspace. Keep in mind that the variables must be of type Simulink.Signal and they must follow the rules detailed in the table in the link below:
2) Set the variable's scope to 'Parameter' and pass them in as function arguments to the MATLAB function block. To do this, add the base workspace variables that you wish to use in the MATLAB function block to the list of function arguments. Then, set the scope of these variables to 'Parameter' as described here:
3) Use constant blocks to import the base workspace variables elsewhere in your model and pass them into the MATLAB function block as input arguments. This requires no modification of the variable scope, but increases the number of blocks in your model.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Workspace Variables and MAT Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!