How to overcome the error

1 次查看(过去 30 天)
Prabha Kumaresan
Prabha Kumaresan 2017-12-22
评论: Star Strider 2017-12-22
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 个评论
Stephen23
Stephen23 2017-12-22
编辑:Stephen23 2017-12-22
@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 2017-12-22
@Stephen — Thank you!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by