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!