# Script not running for different variable size.

2 views (last 30 days)

Show older comments

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
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.

### Accepted Answer

Jan
on 16 Aug 2022

##### 0 Comments

### More Answers (1)

Walter Roberson
on 16 Aug 2022

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!