How to solve the error

3 Ansichten (letzte 30 Tage)
Prabha Kumaresan
Prabha Kumaresan am 20 Dez. 2017
Kommentiert: ANKUR KUMAR am 20 Dez. 2017
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')

Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by