Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Could anybody tell me the working of coding

1 vue (au cours des 30 derniers jours)
Prabha Kumaresan
Prabha Kumaresan le 29 Déc 2017
Clôturé : MATLAB Answer Bot le 20 Août 2021
clear all;
clc;
N_UE=[10 20 30 40 50];
N_SC=[60 70 80 90 100];
for t= 1:length(N_UE)
for r = 1:length(N_SC)
C=rand(N_UE(t),N_SC(r));
N_G=4;%No of group
B = cell(N_G,1);
sumB = cell(N_G,1);
C_copy = C;
for d=1:1:N_G
if d==N_G
sz=length(C_copy(:,1));
e=sz;
else
if d==1
e=randi([1 5]);% select No of UE randomly
else
sz=length(C_copy(:,1));
sz=ceil(sz/2);
e=randi([1 sz]);% select No of UE randomly
end
end
idx=randsample(1:size(C_copy,1),e);
B{d} = C_copy(idx,:);
C_copy(idx,:) = [];
[rows, columns] = size(B{d});
% Get sum of columns and replicate vertically.
sumB{d} = repmat(sum(B{d},1), [rows, 1]);
end
% E=[sumB{1}; sumB{2};sumB{3};sumB{4};sumB{5};sumB{6};sumB{7};sumB{8};sumB{9};sumB{10}];
E=[sumB{1}; sumB{2};sumB{3};sumB{4}];
end
end

Réponses (1)

Walter Roberson
Walter Roberson le 29 Déc 2017
As I posted before, you need to put an upper bound on the number of items you randomly select, and the upper bound needs to be (number of remaining groups minus 1)
I guess I needed to be more explicit: in your code, the number of remaining groups is (N_G - d)
  3 commentaires
Walter Roberson
Walter Roberson le 29 Déc 2017
Change
sz=ceil(sz/2);
to
sz = min(ceil(sz/2), (N_G-d-1));
Prabha Kumaresan
Prabha Kumaresan le 29 Déc 2017
If i change to sz = min(ceil(sz/2), (N_G-d-1)); it results in Error using randi First input must be a positive scalar integer value IMAX, or two integer values [IMIN IMAX] with IMIN less than or equal to IMAX.
Error in line e=randi([1 sz]);% select No of UE randomly.

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by