for loop inside for loop

So I have this vector of number of packets start from 1:1e3 . each single packet have random number of datagrams and each of this datagrams have a size following geometeric distribution. The idea is to find the total size of all datagrams within each packet and for all the packets (from 1:1e3). So I did this code that have 1e3 packets and each packet have a random number of datagrams. but, once I tried to find the total size of all datagrams for all the packets, it only gives me the first total size of packet number 1 then stop. here is my code:
xi=0.91; sigma=74.1; mu=81.5; nof_packets=1000;
p=25;
mean=1/p;
for q=1:nof_packets
n_d(q)=geornd(mean);
for m=1:n_d
datagram_size(m)=gprnd(xi,sigma,mu);
counter=sum(datagram_size);
end
end

5 件のコメント

Sindar
Sindar 2020 年 1 月 20 日
編集済み: Sindar 2020 年 1 月 20 日
Does it error or just end? It looks more likely that it only gives you the size of the last packet, overwriting the earlier ones.
for q=1:nof_packets
n_d(q)=geornd(mean);
for m=1:n_d
datagram_size(m)=gprnd(xi,sigma,mu);
end
counter(q)=sum(datagram_size);
end
total_packets = sum(counter);
(there's probably a cleaner way that doesn't involve loops, but I'm not clear on the structure of your data)
Sindar
Sindar 2020 年 1 月 20 日
Also, I wouldn't use "mean" as a variable name, since it is an important built-in function
talal alqahtani
talal alqahtani 2020 年 1 月 20 日
Hello Sindar,
it just end. and it gives only the first packet size.
Sindar
Sindar 2020 年 1 月 20 日
Does my code work for you?
talal alqahtani
talal alqahtani 2020 年 1 月 20 日
it works perfect. Thank you

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

質問済み:

2020 年 1 月 20 日

コメント済み:

2020 年 1 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by