Info

此问题已关闭。 请重新打开它进行编辑或回答。

Could anybody tell me the working of coding

2 次查看(过去 30 天)
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

回答(1 个)

Walter Roberson
Walter Roberson 2017-12-29
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 个评论
Prabha Kumaresan
Prabha Kumaresan 2017-12-29
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.

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by