function M = hexGroups2d; % Hexgroups - This function places randomly sized groups of evenly spaced points, % which come out as quasi-hexagonal blobs. Total of 100 points. % Calls randgrpsize, which generates the number/composition of the groups, % in a matrix called GS. randgrpsize; % Identifies the no. of groups, (ng), and total number, (N), for later use. ng = size(GS,2); N = 100; GS; % Next, the theoretical radius of each groups is calculated, and placed in a % matrix R,for use in uegrpcntrs to determine minimum distances among group centers. R = []; % Initialize R. for g = 1:size(GS,2) % Loop over all groups. n = GS(1,g); % Pull out the group size from GS. cval = max(2,ceil(sqrt(n))); plac = sqrt(pi * 3.125); r = (cval - 1) * plac; R = [R r]; end % Now, the center points for the groups are generated, based on ng and and the % radii in R, which determine the min distances between group centers. C = uegrpcntrs(ng,R); % Now, the points matrix CPTSN is built, one group at a time. CPTSN = []; % Initialize the CPTSN matrix. for f = 1:ng gs = GS(1,f); % Identifies the individual group % size (f,a column of matrix GS). if gs == 1 % Special case for a group of 1, since CPTS = [0 0 0 0]; % hexgroups has a fit about it. else CPTS = hexgroups(gs); % Generates each group with the hexgroups end % function. V = C(f,:); % Takes the group center location % from matrix C, so that the group % position may be adjusted below. CPTS(:,2) = CPTS(:,2) + V(1,1); % Adjust the x-coordinates. CPTS(:,3) = CPTS(:,3) + V(1,2); % Adjust the y-coordinates. CPTS(:,4) = f; % Attach a group number to each point, % so that groups may be identified. CPTSN = [CPTSN; CPTS]; % Build the matrix. end CPTSN(:,1) = [1:N]'; % Numbers the points (individuals). M = CPTSN; % Final product is labelled M. % plot(UEGPTS(:,2),UEGPTS(:,3),'.') % Plot, for visual check; should be % axis([-60,60,-60,60]) % killed in final version.