How to solve the error
3 views (last 30 days)
Show older comments
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')
1 Comment
ANKUR KUMAR
on 20 Dec 2017
Is this your homework problem? Prog for the same homework question can be found here: https://in.mathworks.com/matlabcentral/answers/373858-could-anyone-tell-me-how-to-execute-the-following-code
Answers (0)
See Also
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!