Problem with for loop in given algorithm

조회 수: 1 (최근 30일)
charu shree
charu shree 2023년 5월 2일
댓글: VBBV 2023년 5월 3일
Hello all, I am trying to code the following statement using for loop but not getting it clearly.
Queue length at a node in time slot 't+1' = Queue length at a node in time slot 't' + number of packets arrival in time slot 't'.
This is what I had tried:
T = 100; % Total slots
nodes = 8 % Total nodes
ini_q_len = 10; % Queue length at node 1 in time slot 't'
n = 10; % number of packets
p = 0.2; % probability of successful arrival of packets
for t = 1:T % each time slot
%% Queue length of each nodes
for i = 1:nodes
X(i) = ini_q_len+ binornd(n,p);
end
end
The problem with this is that I am not getting how to bring in for loop Queue length at a node in time slot 't' i.e., how to include previous slot queue length.
Any help in this regard will be highly appreciated.

답변 (1개)

VBBV
VBBV 2023년 5월 2일
편집: VBBV 2023년 5월 2일
unless Queue length value is not varying, you can initialize it as below and access in 2D matrix to include previous queue length values
T = 100; % Total slots
nodes = 8 % Total nodes
ini_q_len = repmat(10,1,100); % Queue length at node 1 in time slot 't'
K = 4; % some constant
for t = 1:T % each time slot
%% Queue length of each nodes
for i = 1:nodes
X(i,t) = ini_q_len(t)+ K;
end
end
  댓글 수: 13
charu shree
charu shree 2023년 5월 3일
Yes sir....Thanks a lot for your cooperation...really learning a lot from peoples like you...
VBBV
VBBV 2023년 5월 3일
Ok, np, if you think my answer helped solved your problem, please accept it

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

카테고리

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