How to distribute random number of users within the different circles
이전 댓글 표시
Hello Matlab Community,
I generated the random number of points (200 users) within 7 different circles (different radius) in square box of 1000 by 1000 meters as shown in figure. The number of points (users) in each circle are random but fix. I need to distribute the points (shuffle the users) among the mentioned cirlces for example one cirlce has 68 points (users) and other circle has 35 points (users) in the first iteration in the next iteration these users should be changed (shuffle from one cirlce to other circle) but the total number of points (200 users) among these circles in square box of 1000 by 1000 meters remain same.
Thank You!

댓글 수: 9
Riccardo Scorretti
2022년 5월 6일
Can you provide the code so we can run it?
khalid khan
2022년 5월 6일
Adam Danz
2022년 5월 10일
> ...for example one cirlce has 68 points and other circle has 35 points in the first iteration in the next iteration these users should be changed (shuffle from one cirlce to other circle) but the total number of points (200) remain same.
I understand that there will always be 200 points and I think I understand that there will always be 7 cirlces (correct?). And I think I understand that the cirlce each dot belongs to should randomly change between iterations, right?
What I don't undestand is whether the number of dots per cirlce should be the same between iterations.
khalid khan
2022년 5월 10일
편집: khalid khan
2022년 5월 10일
the cyclist
2022년 5월 10일
It is a little difficult what exactly you want to be random, and what you want to be constant. The following would be my understanding:
- Number of users: Constant (200, but notice that your code has 212)
- Number of circles: Constant (7)
- (X,Y) center of each circle: Constant? Use the values from your code?
- Which circle each user "belongs" to: Random, switching every iteration.
- Color of dot: Corresponds to the user, not the circle where they are located. [Color is only the same in each circle because it is your first iteration?]
- Radius of each circle: ????
It seems that you want to radius of the circle to be different, depending on how many users are in the circle. Is that right? Can you be more specific? I couldn't see a pattern in your code between radius and user count.
[Sorry if I am repeating some questions from other helpers.]
khalid khan
2022년 5월 10일
William Rose
2022년 5월 10일
@khalid khan, I too received an email. It appears that you are receiving excellent advice from @the cyclist and @Adam Danz and @Riccardo Scorretti, so I don;t think you need me.
khalid khan
2022년 5월 10일
채택된 답변
추가 답변 (1개)
That's ok?
% Coordinates (x0,y0), radius (rad) and number of users (nbu) for each circle
x0 = [100 450 500 650 900 900 800];
y0 = [700 200 600 500 400 100 850];
rad = [ 30 40 50 30 35 35 30];
nbu = [ 25 35 68 15 44 10 15];
% Generate the users
nbu_tot = sum(nbu);
x = zeros(nbu_tot, 1); % it is better to pre-allocate matrix, when possible
y = zeros(nbu_tot, 1);
grp = zeros(nbu_tot, 1); % group to which each user belongs
base = 0;
for n = 1 : numel(nbu)
ind = base + (1:nbu(n)); % = index of the users
t = 2*pi*rand(nbu(n), 1);
r = rad(n)*sqrt(rand(nbu(n), 1));
x(ind) = x0(n) + r.*cos(t);
y(ind) = y0(n) + r.*sin(t);
grp(ind) = n;
base = base + nbu(n);
end
% Now, just shuffle the groups
grp = grp(randperm(nbu_tot));
% Plot the users
colors = 'rgbkmc'; % many colors ...
figure
for n = 1 : numel(nbu)
t = find(grp == n);
col = colors(1+mod(n,numel(colors)));
plot(x(t), y(t), [col '.'], 'MarkerSize', 5);
hold on
end
axis square ; grid on
It's a little bit different from your original code. The coordinates of all users are in vectors x and y. All users are grouped together; the group to which each user belong is stored in the vector grp.
댓글 수: 3
khalid khan
2022년 5월 9일
Riccardo Scorretti
2022년 5월 9일
I have two questions about the statement "the users in one cirlce is 25 now some of the these users move from this cirlce and to an other circle due the mobility of the users radius of circle should be dcrease or inecrease at each iteration":
- All users are supposed to move at the same time, or one by one?
- When user moves away from a circle to another, that circle is required to become smaller. How much smaller?
- What happens if, due to shrinking of a circle, some users (which was not supposed to move) find themselves outside of any circle?
- What happens if, due to expandinging of a circle, some users (which was not supposed to move) find themselves inside more than a single circle?
khalid khan
2022년 5월 9일
편집: khalid khan
2022년 5월 9일
카테고리
도움말 센터 및 File Exchange에서 MATLAB Parallel Server에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






