Variable scope in Simulink .mdl files
显示 更早的评论
I am trying to address a Simulink .mdl file in a call to linmod from a Matlab function, and I get an "undefined variable" error. I used a "load" command prior to calling the linmod function that contained the variable and then used a "whos" to verify that the variable was in the calling space (it was), but I still get the error. In an older version of the code I declared the variable as global which worked, but since I am eventually going to define it as a distributed processing job, I need to change it (global variables are not permitted). How would I get the Simulink model to recognize the upstream variables?
采纳的回答
更多回答(1 个)
Arnaud Miege
2011-4-11
1 个投票
linmod uses data that is in the base workspace, not in the function workspace. For a workaround, see: http://www.mathworks.com/support/solutions/en/data/1-15MSCA/?solution=1-15MSCA
I am not sure however, if that would work as part of a distributed processing job.
HTH,
Arnaud
3 个评论
Arnaud Miege
2011-4-11
A workaround might be to copy all the necessary data into the model workspace to make it self-contained.
QinetiQ378 Scanlon
2011-4-11
Arnaud Miege
2011-4-11
What I was suggesting was to load the MAT file in the MATLAB workspace, then using Model Explorer, copy the data from the base workspace into the model workspace (select all, CTRL+C and CTRL+V), before saving the model.
An alternative might be to insert the code that loads the MAT file as a model callback (InitFcn or PreLoadFcn) and making sure that the MAT file is included in the file dependencies when distributing the jobs to the workers.
类别
在 帮助中心 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!