SimEvents: is it possible to change event action variable from script?

9 ビュー (過去 30 日間)
Ken Kwon
Ken Kwon 2019 年 8 月 21 日
回答済み: Uri 2023 年 2 月 2 日
Hi. I'm trying to run multiple iterations of SimEvent simulation while sweeping one variable in the model.
Let's say I have an entity with attribute called 'Route', within initial value of 1.
I have this event action in the entity server named 'Entity Server 1'
x = rand;
threshold= 0.5;
if x>threshold
entity.Route = 2;
end
Following the Entity server is 2 port Entity Switch that uses attribute 'Route' to divert entity accordingly.
Is it possible to change variable 'threshold' value from script? I'm trying to plot end output parameter vs threshold plot.
Thank you
  1 件のコメント
Uri
Uri 2023 年 2 月 2 日
I am facing the same issue
I have some model in simevents and some code inside an server action block and there is just no good way to debug those. Wierd of them to put a mini editor with no good way to debug

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

回答 (2 件)

Jalaj Gambhir
Jalaj Gambhir 2019 年 8 月 27 日
Hi,
I believe variable declared within a block parameter of Simulink block might not be accessible from the MATLAB as it goes out of scope.
However, a possible workaround could be by saving the different threshold value at each iteration in a ‘.mat’ file and then loading the saved value with the ‘Entity action’ tab. You can get an idea from the following script:
values = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9];
for i=1:length(values)
threshold = values(i);
save('dump.mat','threshold');
simOut = sim('yourModelName');
end
And in the Entity Action tab:
x = rand;
th = load('dump.mat','threshold');
entity.Route = 1;
if x> th.threshold
entity.Route = 2;
end

Uri
Uri 2023 年 2 月 2 日
If you want a workaroun to that you can create a simulink function lets say setAttribute(u) and call it from within the event action with u being the variably you would like to see outside and connect the whole thing like that:
so I am calliing from inside the enitity block:
setAttribute(variableIWant);

カテゴリ

Help Center および File ExchangeDiscrete-Event Simulation についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by