How do I access model workspace variables in simulink/simevents?

I have varying transport times in a discrete events system. I have created a matrix of the times in the model workspace but I cannot find how i access that variable from within the model.
I currently have a Attribute function where I try to access the model workspace. How do I do?

回答 (1 件)

Sainath Varikuti
Sainath Varikuti 2015 年 4 月 29 日
編集済み: Sainath Varikuti 2015 年 4 月 29 日

0 投票

You can view the model workspace variables in Model Explorer or use the methods of Simulink.ModelWorkspace class to operate on model workspace variables.

3 件のコメント

Mats
Mats 2015 年 5 月 15 日
Thanks, that got me one step on the way, but I still cannot read it. I cannot seem to run the getVariable command without error. It works in debug mode (in command window) but not in running. My code:
function y = fcn(State, traveltime)
%#codegen
coder.extrinsic('get_param');
hws = get_param('test1','modelworkspace');
traveltime = hws.getVariable('traveltime');
traveltime;
switch State
case 1
from=1;
to=3;
case 2
from=3;
to=4;
case 3
from=4;
to=2;
end
y = traveltime(from,to);
Sebastian Castro
Sebastian Castro 2015 年 5 月 15 日
Why do you need to use get_param and getVariable if the entire model already has access to the model workspace?
Instead, I would suggest you define a "parameter" scoped variable in your MATLAB Function, which will inherit its value from the Model Workspace. To do this, you can use the Model Explorer and navigate to the MATLAB Function block itself to add new data.
Then, you should be able to reference traveltime as you would any other variable.
- Sebastian
Ryan Livingston
Ryan Livingston 2015 年 6 月 2 日
Documentation for Sebastian's comment is here. See the section Setting Data Scope for how to change the scope to a parameter.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSimulink Functions についてさらに検索

製品

質問済み:

2015 年 4 月 28 日

コメント済み:

2015 年 6 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by