Script not running for different variable size.

2 views (last 30 days)
I am running this code for Total_time = 1000 and it is working fine but when I increase this variable to 100000, it is not showing any results. can anyone help me for this.
Code:
close all;
clear;
clc;
% Defining variables
A = 20; % Total number of transmitters
p = 0.01;
Length_of_packet = 1000; % Maximum packet length in bits
Bitrate = 100; % bit rate for each transmitter in bits/sec
Trasmission_Time = Length_of_packet/Bitrate;
Total_Time = 1000; % Total time for simulation in seconds
Zero_slot_overlapping = 0; % Calulation overlapping Timeslots
One_slot_overlapping = 0; % Calulation overlapping Timeslots
Two_slot_overlapping = 0; % Calulation overlapping Timeslots
Three_slot_overlapping = 0; % Calulation overlapping Timeslots
Four_slot_overlapping = 0; % Calulation overlapping Timeslots
Five_slot_overlapping = 0; % Calulation overlapping Timeslots
Six_slot_overlapping = 0; % Calulation overlapping Timeslots
Seven_slot_overlapping = 0; % Calulation overlapping Timeslots
Eight_slot_overlapping = 0; % Calulation overlapping Timeslots
Nine_slot_overlapping = 0; % Calulation overlapping Timeslots
Ten_slot_overlapping = 0; % Calulation overlapping Timeslots
User = zeros(A,Total_Time);
for k = 1:A
for i = 1:(Total_Time-10)
probability_of_transmission = rand(1);
if probability_of_transmission > p
User(k,i) = 0;
else
User(k,i) = 1;
end
end
end
% for k = 1:A
% X = sum(User(k,:));
% end
for k = 1:A
idx = find(User(k,:)==1);
[a,b] = size(idx);
for i = 1:b
for j = 1:Trasmission_Time
User(k, (idx(i)+j-1)) = 1;
User(k, (idx(i)+j+10)) = 0;
end
end
end
X = sum(User(User == 1));
Total_no_of_packets_transmitted = (round(X,-2))/10
Number_of_overlapping_packets_per_column = sum(User);
% % Create all possible row combinations
% a1 = 1:numel(User(1,:));
% a2 = 1:numel(User(:,1));
% a3 = combvec(a1,a2)';
%
% % Assign columns of a3 to R1 and R2 to make the code readable
% R1 = a3(:,1);
% R2 = a3(:,2);
%
% % finding the overlapps and counting them
% z = sum(and(User(R1,:),User(R2,:)),2);
%
% % Table the data
% overlapping = table(R1,R2,z)
%Creating row pairs to compare
row_pairs = nchoosek(1:size(User,1),2);
%disp(row_pairs);
number_of_pairs = size(row_pairs,1);
number_of_overlaps = zeros(number_of_pairs,1);
%Finding overlapping and counting them
for ii = 1:number_of_pairs
number_of_overlaps(ii,1) = nnz(User(row_pairs(ii,1),:) & User(row_pairs(ii,2),:));
if number_of_overlaps(ii,1) == 0
Zero_slot_overlapping = Zero_slot_overlapping + 1;
elseif number_of_overlaps(ii,1) == 1
One_slot_overlapping = One_slot_overlapping + 1;
elseif number_of_overlaps(ii,1) == 2
Two_slot_overlapping = Two_slot_overlapping + 1;
elseif number_of_overlaps(ii,1) == 3
Three_slot_overlapping = Three_slot_overlapping + 1;
elseif number_of_overlaps(ii,1) == 4
Four_slot_overlapping = Four_slot_overlapping + 1;
elseif number_of_overlaps(ii,1) == 5
Five_slot_overlapping = Five_slot_overlapping + 1;
elseif number_of_overlaps(ii,1) == 6
Six_slot_overlapping = Six_slot_overlapping + 1;
elseif number_of_overlaps(ii,1) == 7
Seven_slot_overlapping = Seven_slot_overlapping + 1;
elseif number_of_overlaps(ii,1) == 8
Eight_slot_overlapping = Eight_slot_overlapping + 1;
elseif number_of_overlaps(ii,1) == 9
Nine_slot_overlapping = Nine_slot_overlapping + 1;
elseif number_of_overlaps(ii,1) == 10
Ten_slot_overlapping = Ten_slot_overlapping + 1;
% elseif n_overlaps(ii,1) == 11
% Four_slot_overlapping = Four_slot_overlapping + 2;
% Three_slot_overlapping = Three_slot_overlapping + 1;
end
end
%disp([row_pairs number_of_overlaps]);
B = ([Zero_slot_overlapping; One_slot_overlapping; Two_slot_overlapping; Three_slot_overlapping; Four_slot_overlapping; Five_slot_overlapping; Six_slot_overlapping; Seven_slot_overlapping; Eight_slot_overlapping; Nine_slot_overlapping; Ten_slot_overlapping] );
T = num2cell(B)
[Zero_slot_overlapping, One_slot_overlapping, Two_slot_overlapping, Three_slot_overlapping, Four_slot_overlapping, Five_slot_overlapping, Six_slot_overlapping, Seven_slot_overlapping, Eight_slot_overlapping, Nine_slot_overlapping, Ten_slot_overlapping] = deal(T{:});
  4 Comments
Jan
Jan on 16 Aug 2022
Edited: Jan on 16 Aug 2022
You can simplify your code. Replace e.g.
User = zeros(A,Total_Time);
for k = 1:A
for i = 1:(Total_Time-10)
probability_of_transmission = rand(1);
if probability_of_transmission > p
User(k,i) = 0;
else
User(k,i) = 1;
end
end
end
by
User = zeros(A, Total_Time);
User(:, 1:Total_Time - 10) = rand(A, TotalTime - 10) > p;
The code will be much shorter and easier, if you do not hide an index in the names of the variables like in "<Zero>_slot_overlapping" but use a vector and a real index (starting at 1 instead of 0).
The result for 1000000 might be correct: If the random signals are not overlapping.

Sign in to comment.

Accepted Answer

Jan
Jan on 16 Aug 2022
The empty result looks correct: The larger the time, the fewer overlapping slots you find. For Total_Time=1000 there are about up to 40 overlapping slots, for Total_time=2000 about up to 8 and for 3000 less than 4. For 10'000 the code finds overlapping slots in rare cases only.

More Answers (1)

Walter Roberson
Walter Roberson on 16 Aug 2022
The problem is that you stop counting at 10 overlaps. As the time increases, the number of overlaps increases, until you get to the point where all of the overlaps have counts more than 10, leaving the low bins with no entries.
  4 Comments
Prashant Bhagat
Prashant Bhagat on 16 Aug 2022
Thanks. I will try and let you know about it.

Sign in to comment.

Categories

Find more on Digital Input and Output in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by