Getting undefined model variables
古いコメントを表示
Hello, I would like to ask if there is a proper way to get information about Simulink model's variables that are not set in the workspace. I mean before I run it and get an error message. Thank you, Adam
2 件のコメント
Arnaud Miege
2011 年 4 月 11 日
I don't understand your question, can you clarify and elaborate?
Walter Roberson
2011 年 4 月 11 日
My personal interpretation was,
Is there a way to analyze a model before running it, to determine the model variables that should be initialized from the workspace, but for which the workspace variable has not been initialized?
(I can see how such a thing could be useful, so you don't waste your time running through a number of steps only to have the program fall over because you forgot to initialize something. On the other hand, my training in computing theory suggests to me that the answer is "You cannot _reliably_ do this."
採用された回答
その他の回答 (2 件)
Arnaud Miege
2011 年 4 月 11 日
0 投票
If Walter's interpretation is correct, you can maybe use Simulink.findVars, but I think that probably requires the variables to be defined in the first place. Also note the limitations as to what it can and can't find. That's been available since R2010a.
HTH,
Arnaud
Rob Graessle
2011 年 4 月 11 日
You could place something like this in the InitFcn callback of your model:
if ~exist('a', 'var') % If 'a' is not initialized
a=3; % Initialize it...
disp('Variable a not initialized!'); % ...or display an error
end
This would only work for variables in the MATLAB base workspace though, not the model workspace.
カテゴリ
ヘルプ センター および File Exchange で Event Functions についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!