How to apply IF statement to entity attribute
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I'm new to Matlab and Simulink. Right now my entity have two attributes, entity.FeePaid and entity.Age. I want to set rule where if (entity.FeePaid > 2.3) && (entity.Age > 1) only then it can enter queue else the entity will be dropped. I've tried using IF and SWITCH but it cannot retrieve the attribute. I'm trying to use ENTITIES GATE but I have no idea how to configure it (still trying to look for solution). Anyone has any idea how to solve this or what I'm doing wrong? I'm using Matlab R2019a. Thanks in advance.
3 commentaires
Réponses (1)
Ashok
le 22 Nov 2024
Modifié(e) : Ashok
le 22 Nov 2024
From the attached screenshot, it looks like two different entity types, 'Attacker' and 'Legitimate', are being combined into a single queue using an 'Entity Input Switch' block. This approach isn't feasible. More details can be found here:
Regarding filtering entities based on attribute values, the 'Simulink Function' block allows for implementing functions, including relational expressions, using Simulink blocks. The attached file 'example_R2019a.slx' demonstrates this.
In the example, the 'User Entity Gen' subsystem generates entities of type 'User' with attributes (FeePaid, Age). These entities can have two possible attribute combinations: (0, 0) or (5, 2).
When an entity enters 'Entity Server 1', the 'Check_fn' function is called, passing the entity's attributes as arguments.
The 'Simulink Function' block, 'Check_fn', applies the logical condition (FeePaid > 2.3) && (Age > 1) and outputs a control signal.
This control signal directs the 'Entity Output Switch' to send the entity down the appropriate path. The rest of the model is for visualizing the filtered entities. Signal viewers inside the 'recordOutEntityFeeAge' function display the 'FeePaid' and 'Age' attributes of the filtered entities.
For more information about the 'Simulink Function' block, run the following command in the MATLAB Command Window.
web(fullfile(docroot, 'simulink/slref/simulinkfunction.html'))
I believe this will assist you!
0 commentaires
Voir également
Catégories
En savoir plus sur Route Entities and Simulink Messages dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!