Matrix with fix number of ones

1 visualizzazione (ultimi 30 giorni)
Hello guys, I want to design a matrix whose elements are 1 when the probability for that index is higher than certain probability otherwise it should be zero and When the index has 1 then the following 10 index of the same row should be one. I tried it with the below code but it is not working. Can any one help me with that. Thanks in advance.
close all;
clear;
clc;
% Defining variables
A = 10 ; % Total number of transmitters
p = 0.05;
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 = 1000000; % Total time for simulation in seconds
User = zeros(length(A),Total_Time);
for jj = 1:length(A)
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
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;
end
end
end
  2 Commenti
Prashant Bhagat
Prashant Bhagat il 26 Ago 2022
The problem with this code is sometimes this code is generating more than 10 consequtive ones which i don't want.
Walter Roberson
Walter Roberson il 2 Set 2022
You are correct, my code does not prevent the case that after generating a block, that it then immediately generates another block. It would be necessary to code stuffing in a 0 after the block of values. But before I do that, I would request clarification:
  • suppose that there would be a random occurance that would happen less than 10 elements from the end of the time: should that be prevented, or should it be permitted and the buffer should be filled up to the end of what is present? If there is a "time budget" then it would make sense not to transmit something close to the end of the time, but if this is a simulation of an extended process, then the simulated values should look like the "prefix" of an extended simulation, so there should not be any special treatment at the end of the time
  • right at the end of the time, can the values end with a 1, or should they end with a 0 always? Is the 0 a "terminator", or an "inter-group gap"? What is the reason in the model that you cannot have multiple consecutive occuppied groups?

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 26 Ago 2022
for jj = 1:length(A)
for k = 1:A
skipping = 0;
for i = 1:(Total_Time-10)
if skipping > 0
User(k,i) = 1;
skipping = skipping - 1;
else
probability_of_transmission = rand(1);
if probability_of_transmission > p
User(k,i) = 0;
else
User(k,i) = 1;
skipping = 10;
end
end
end
end
However, I suspect you should be using probability_of_transmission <= p rather than > p

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by