How to overcome the error

2 visualizaciones (últimos 30 días)
Prabha Kumaresan
Prabha Kumaresan el 22 de Dic. de 2017
Comentada: Star Strider el 22 de Dic. de 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 comentarios
Stephen23
Stephen23 el 22 de Dic. de 2017
Editada: Stephen23 el 22 de Dic. de 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 el 22 de Dic. de 2017
@Stephen — Thank you!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Performance and Memory en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by