How to overcome the error

2 views (last 30 days)
Prabha Kumaresan
Prabha Kumaresan on 22 Dec 2017
Commented: Star Strider on 22 Dec 2017
N_UE=[2 4 6 8 10];
numGroups = 5;
for t= numGroups:length(N_UE)
% divisions = sort(randperm(numGroups,t) , 'ascend')
divisions = sort(randperm(t,min([t numGroups])) , 'ascend')
% divisions = sort(randperm(t,numGroups) , 'ascend')
divisions = [0, divisions, t]
% 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} = t(indexes);
end
celldisp(groups);
end
If i run the code i am getting Error in (line 16)
groups{k} = t(indexes);
Attempted to access t(2); index out of
bounds because numel(t)=1.
could anyone tell me how to overcome it.
  2 Comments
Stephen23
Stephen23 on 22 Dec 2017
Edited: Stephen23 on 22 Dec 2017
@Prabha Kumaresan: please stop spamming the same question repeatedly. It does not get you help faster, but in fact makes it harder for us to help you. I closed the duplicates.
Star Strider
Star Strider on 22 Dec 2017
@Stephen — Thank you!

Sign in to comment.

Answers (0)

Categories

Find more on Performance and Memory in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!