Filter löschen
Filter löschen

Triggering functions in Event Actions @ SimEvents

6 Ansichten (letzte 30 Tage)
PersistentNoob am 2 Mär. 2024
Beantwortet: Divyanshu am 2 Apr. 2024
Consider functions that take/give Tables as input/output like e.g:
function [ScaledTable] = ScaleMyTable(Table, Multiplier)
ScaledTable = Table.*Multiplier;
function [Table] = ClearTableColumn(ScaledTable, Column)
Table = RefTable(:,Column) = [];
I have a server in a SimEvents model. I would like to use Event Actions to call custom functions that operate on tables by using entities attributes, and operate on enties attributes by using values from tables. For example:
%% Entry Action:
ScaledTable = ScaleMyTable(Table, entity.Attribute1);
entity.Attribute3 = max(ScaledTable(:, entity.Attribute2));
Table = ClearTableColumn(ScaledTable, entity.Attribute4)
The simulation won't run because apparently some MATLAB workspace-defined classes like tables, structs etc. are not supported in Event Actions, and I don't understand how to circumvent the problem. I have tried using a MATLAB function block connected to "From Workspace/To Workspace" blocks and trigger that function from Event Actions, but the error message is the same.
"Error in [...] block. See Entry action line [...].
Caused by: Data type of parameter [...] is not supported in event actions [...]."
Further down the line there are gates controlled by signals; these signals are obtained by "From Workspace" blocks which reference columns of these tables, converted to timeseries. So, my goal(s) are something like:
  • Use an Event Action to trigger a function that receives a Table as an input and give a Table as an output
  • Do something with a Table (like assign a certain table entry to an entity's attribute)
  • Making sure that the Table is updated at runtime so that the timeseries that control the entity gates further down the line are updated as well
What am I missing here? Is this just a flawed design, and do I have to tackle the problem another way? Thanks.

Antworten (1)

Divyanshu am 2 Apr. 2024
Hi PersistentNoob,
I have created a sample model using SimEvents Blocks. I have created a sample MATLAB function 'scaled_value' which is triggered from Event Actions of an Entity Server Block used in the Model. The model simulates without any error.
Here is the code for function 'scaled_value':
function [result] = scaled_value(val,tb)
for i=1:5
tb{i,1} = tb{i,1}*val;
res = max(tb{:,1});
result = res;
Below is the piece of code written for Event Actions in 'Entity Server' Block:
d = [1;2;3;4;5];
Vnames = {'data'};
t = table(d,'VariableNames',Vnames);
entity.CurrentGasLevel = scaled_value(entity.CurrentGasLevel,t);
I followed the following example to create sample model and made customizations as per the description provided:
Hope it helps!


Mehr zu Discrete-Event Simulation finden Sie in Help Center und File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by