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

1 visualizzazione (ultimi 30 giorni)
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 Commento
Uri
Uri il 2 Feb 2023
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

Accedi per commentare.

Risposte (2)

Jalaj Gambhir
Jalaj Gambhir il 27 Ago 2019
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 il 2 Feb 2023
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);

Categorie

Scopri di più su Discrete-Event Simulation in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by