How do I access base workspace variables from a MATLAB Function Block?
111 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2019-7-22
编辑: MathWorks Support Team
2023-6-15
How do I access base workspace variables from a MATLAB Function Block?
采纳的回答
MathWorks Support Team
2023-6-15
编辑:MathWorks Support Team
2023-6-15
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!