下面的代码告诉我,我需要使用不同的种子来生成10次随机数,然后对它们进行平均以得到更平滑的图形。我没有使用Matlab的丰富经验,因此即使阅读了文档,我也不了解这些种子的工作原理。
% Create an array
S = 0:20;
CW = 0:5:100;
S(1) = 0;
CW(1) = 0;
counter = 2; % Counter for the nuber of S
N = 20; % Number of nodes
% Collect data for each increment of 5 up to 100 for CW values
for i = 5:5:100
T = 10000 / i; % Total number of cycles
% Create array of next transmission times for N nodes
transmission_time = floor(i * rng(1, N));
total_success = 0;
% Loop for T cycles
for t = 1:T
% For 0 to the number of contention windows
for pos = 0:i-1
% Count the number of nodes that have the current CW
count = 0;
for node = 1:N
if transmission_time(node) == pos
count = count + 1;
end
end
% If there is more than 1, then a collision occurs
collision = false;
if count > 1
collision = true;
% If there is exactly 1, then there is a success
elseif count == 1
total_success = total_success + 1;
end
% If there is a collision, reassign new transmissions times
if collision == true
for node = 1:N
if node == pos
transmission_time(node) = floor(i * rand(1));
end
end
end
end
end
% Display the ratio of successes
S(counter) = total_success / (T * i);
counter = counter + 1;
end
% Plot the graph for Success vs CW
plot(CW, S, 'o-');
xlabel('Contention Window, CW');
ylabel('Throughput, S');
对不起,所有的混乱。我认为你们中的一些人说对了,因为我不需要生成不同的流。
在上面的代码中,有一行显示“ if node == pos”,这是不正确的,应为“ if transmission_time(node)== pos”。
那条线使我的图表变得一团糟。我还需要为成功的数据包生成新的随机数。
谢谢您的所有建议!现在,我对Matlab中的种子如何使用随机性有了更多的了解!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句