function ESEGPTS = squareEvenGroups2d(npg); % ESEvengroups(npg) - This function will place 100 points into groups, with equal % numbers in each. Each group will be evenly-spaced, i.e. in a square. % % User inputs the number of individuals per group (npg); this must be a number % which is a perfect square, or a 2. I.e., only 100, 25, 4, and 2 are valid, % since there must be 100 total individuals. ng = 100 / npg; N = 100; % Now, the center points for the groups are generated. C = eegrpcntrs(ng); CPTSN = []; % Initialize the CPTSN matrix. for p = 1:ng % Loop over all centers to make a % group for each. V = C(p,:); % Pulls out one p at a time. % Pairs have to be generated in a different way. if npg == 2 % For pairs, the second point is placed "manually", using the % spacing constant (since trying to do pairs with evenptsf causes % havoc and chaos). CPTS = [ 0 0; (sqrt(3.125*pi)) 0]; CPTS(:,1) = CPTS(:,1) + V(1,1); % Adjust the x-coordinates. CPTS(:,2) = CPTS(:,2) + V(1,2); % Adjust the y-coordinates. CPTS(:,3) = p; % Identifies group no. of a point. elseif npg ~= 2 CPTS = evenptsf(npg); % Generate the group. CPTS(:,1) = CPTS(:,1) + V(1,1); % Adjust the x-coordinates. CPTS(:,2) = CPTS(:,2) + V(1,2); % Adjust the y-coordinates. CPTS(:,3) = p; % Attach a group number to each point, % so that groups may be identified. end CPTSN = [CPTSN; CPTS]; % Build the matrix. end % Close the loop. CPTSNN = [[1:N]' CPTSN]; % Number the points. ESEGPTS = CPTSNN; % Final product is labelled ESEGPTS. % plot(ESEGPTS(:,2),ESEGPTS(:,3),'.') % Plot, for visual check; should be % axis([-60,60,-60,60]) % commented in final version.