Variable scope in Simulink .mdl files
Mostrar comentarios más antiguos
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?
Respuesta aceptada
Más respuestas (1)
Arnaud Miege
el 11 de Abr. de 2011
1 voto
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 comentarios
Arnaud Miege
el 11 de Abr. de 2011
A workaround might be to copy all the necessary data into the model workspace to make it self-contained.
QinetiQ378 Scanlon
el 11 de Abr. de 2011
Arnaud Miege
el 11 de Abr. de 2011
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.
Categorías
Más información sobre Programmatic Model Editing en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!