How to overcome the error
2 views (last 30 days)
Show older comments
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
Answers (0)
See Also
Categories
Find more on Performance and Memory 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!