I used entity gate to control the entities and got my desired result, but do let me know if there is any more appropriate logarithm for this job.
How to Generate Multiple Entities at Time 10 (sim events)
3 views (last 30 days)
Show older comments
I am a beginner and wants to generate multiple entities at time 10. I found the following code to generate 10 entities at time 0, however, I could not understand it that what should I change to generate entities after a specific time.
Code
N=10;
persistent dtArray index
if isempty(dtArray)
dtArray = [zeros (1, N) inf];
index = 1;
end
dt = dtArray (index);
index = index + 1;
Answers (1)
Altaïr
on 23 Apr 2025
Edited: Altaïr
on 23 Apr 2025
Here is an explanation of the code mentioned in the query. The variable 'dt' represents the intergeneration time, which defines the interval before the next entity is generated. The following line indicates that the first N+1 entities are generated without any delay between them, and there is an infinite interval before the (N+2)th entity is generated. This ensures that only N+1 entities are created in total.
dtArray = [zeros(1, N) inf];
A more flexible approach would be to specify the exact timestamps at which entities should be generated. The following example demonstrates how this can be achieved:
persistent dtArray index timestamps;
if isempty(dtArray)
% Timestamps array when entities should be generated
timestamps = [10,10,10];
% Calculate the intergeneration time
dtArray = [timestamps(1) diff(timestamps)];
% Add Inf at the end to stop generation after last timestamp
dtArray = [dtArray Inf];
index = 1;
end
dt = dtArray(index);
index = index + 1;
This code generates three entities at the 10th second, as specified in the timestamps array.

Feel free to play with the timestamps array and observe how the entity generation is affected. For additional details, the Specify Intergeneration Times for Entities documentation page can be accessed with the following command:
web(fullfile(docroot, 'simevents/ug/specifying-intergeneration-times-for-entities.html'))
0 Comments
See Also
Categories
Find more on String in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!