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

조회 수: 2 (최근 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 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