How do I access base workspace variables from a MATLAB Function Block?
96 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 22 Juil 2019
Modifié(e) : MathWorks Support Team
le 15 Juin 2023
How do I access base workspace variables from a MATLAB Function Block?
Réponse acceptée
MathWorks Support Team
le 15 Juin 2023
Modifié(e) : MathWorks Support Team
le 15 Juin 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Workspace Variables and MAT Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!