How to solve the error

3 次查看(过去 30 天)
Prabha Kumaresan
Prabha Kumaresan 2017-12-20
评论: ANKUR KUMAR 2017-12-20
Please help me to execute the following code
clear all;
clc;
N_UE = [2 4 6 8 10]; % number of users
N_SC = [20 30 40 50 60]; % number of subcarriers
for t = 1:length(N_UE)
for r = 1:length(N_SC)
G=rand(N_UE(t),N_SC(r))% random selection of users and subcarriers
% subcarrier allocation to users%
siz = size(G);
idx = sub2ind(siz, randi([1,N_UE(t)], 1, siz(2)),1:siz(2));
C = zeros(siz);
C(idx) = G(idx);
s = randperm(N_UE(t))
% s = randperm(length(N_UE))
numGroups = 5; % Need to divide s up into 5 groups
divisions = sort(randperm(C, numGroups) , 'ascend')
% divisions = sort(randperm(numUsers-2, numGroups-1) + 1, 'ascend')
divisions = [0, divisions, C]
% Create cell array with random number of users in each groups
groups = cell(1, numGroups);
for k = 1 : numGroups
indexes = divisions(k)+1:divisions(k+1);
% Assign users to the kth group:
usersInThisGroups = length(indexes);
fprintf('Assigning %d users (indexes %d to %d) to group %d.\n', ...
usersInThisGroups, divisions(k)+1,divisions(k+1), k);
groups{k} = s(indexes);
end
celldisp(groups); % D
end
end
as i am getting Error using randperm Inputs must be nonnegative scalar integers.
Error in two (line 25) divisions = sort(randperm(C,numGroups) ,'ascend')

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by