Find variable in Simulink blocks

In a Simulink model 'myModel', I would like to find all blocks that use the variable 'myVariable', even before the variable's value exists in the workspace. The variable appears in several constant blocks, which I want to highlight. But the following approach produces the error below. What am I doing wrong?
Simulink.findVars('myModel', 'Name', 'myVariable')
Model 'myModel' failed to successfully compile, any cached results may be incomplete.
Caused by: Error evaluating expression 't_total' for 'Stop time' specified in the Configuration Parameters dialog for block diagram 'myModel': Undefined function or variable 't_total'.

 채택된 답변

Kaustubha Govind
Kaustubha Govind 2012년 3월 7일

5 개 추천

The particular error that you are seeing is about t_total being undefined, but in general, you do need to define all variables being used in the model (including 'myVariable'). Simulink attempts to compile the model (equivalent to Ctrl+D) in the algorithm used to find the variables, and Ctrl+D will fail if you have not defined the required variables.

댓글 수: 2

K E
K E 2012년 3월 7일
Thanks. I did have to create all variables in the workspace before being able to find myVariable. Here is how to highlight the blocks containing the variable, in case someone finds it useful:
thisVar = Simulink.findVars('myModel', 'Name', 'myVariable')
hilite_system(thisVar.UsedByBlocks,'find')
And this demo was helpful, http://www.mathworks.com/videos/simulink/find-variables-used-by-a-simulink-model.html
K E
K E 2012년 3월 7일
And to turn off highlighting,
hilite_system(thisVar.UsedByBlocks,'none')

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by