MATLAB: How to give entities an attribute from a file

allocationattributeMATLABsimulink

My Time-based entity generator generates standard entities and i want to give them attributes. Therefore I added a Set Attribute block. My entities need to be allocated to one of the 5 available servers. I have a vector with 1000 values, for the first 1000 entities, with the server to which they should be allocated. So this is a vector with [1;1;1;1;1;1;2;1;…..;4;5;1]. I have the vector in a file: Allocation.m. How do I add the server to which each entity should be allocated to the entity with this vector?

Best Answer

Say you define the vector in the m-file:
myVec = [1,2,4,5,2,3...1,1,1]; %server numbers
And you want to assign the next entity with the next element in the vector. You can use an Attribute Function (MATLAB Function for SimEvents) and Persistent Variables to keep the order of the vector.
In the block you would have code like this:
persistent counter
counter = counter+1;
out_newAttribute = myVec(counter);
This should iterate the counter every time a new entity enters the MATLAB function and assign the portion of myVec (server routing) to the entity.