How to overcome the error
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!