how to Use cumsum for a random variables of times to reach a certain value

조회 수: 1 (최근 30일)
I have a data of random times and in the other hand a current simulation time ( slots ) and each slot is 3.5 seconds then 7 seconds and so on. How can I compare the current simulation time with the random times and fit the times that belong to each slot. I'm thinking of cumsum . can that work ?
  댓글 수: 2
Jan
Jan 2019년 7월 30일
Hard to guess. I assume: Yes.
Please explain the dta in detail, because "a data of random times" is not clear enough. Which type and size? Post some example in valid Matlab code, such that we can post a matching code.
talal alqahtani
talal alqahtani 2019년 7월 30일
Baiscily I have number of packets sizes and thier time increments which been generated randomly. the idea is to check the time increments and keep a counter of the simulation time so the begening is Zero then 3.5 then 7 and so on. so that will be the total amount of time. the idea is to compare this simulation time with the packets time increments and see if there a new packet has been generated or not. time increment file is asttached .

댓글을 달려면 로그인하십시오.

채택된 답변

Ajay Pattassery
Ajay Pattassery 2019년 8월 2일
I understand that you have packet arrival times generated randomly and I assume you want to find the number of packet arrival in timeslots of width 3.5 seconds.
Let’s take the following example, where ‘incrementArrival’ is the time increments on which packets are generated. (Output of the Workbook.xlsx file you provided)
incrementArrival = [0 0.2 1 2.5];
Cumsum gives the actual time of arrival of each packet. You could refer to the documentation of cumsum for more info.
packetArrival = cumsum(packetArrival)
packetArrival =
0 0.2000 1.2000 3.7000
If you want to find the number of packets that arrived in slots of 3.5 seconds, you could use histcounts. 'slotEndTime' is the end time of the slots(Assumed 2 slots ranging from 0 to 3.5 and 3.5 to 7)
slotEndTime = 7;
packetInslots = histcounts(packetArrival,[0:3.5:slotEndTime])
packetInslots = 3 1
That is 3 packets arrived in the first time slot(0 to 3.5) and 1 packet in the second slot(3.5 to 7)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by