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

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Discrete-Event Simulation 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by