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')
  댓글 수: 1
ANKUR KUMAR
ANKUR KUMAR 2017년 12월 20일
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

댓글을 달려면 로그인하십시오.

답변 (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