function GPTS = evenGroups2d(npg,randtype); % Evengroups(npg,randtype) - this script will place 100 points into groups of % equal size. User inputs are the number-per-group desired (npg), and the % method of placement (randtype). Entering 'u' for *randtype* gives random % uniform placement. Entering 'n', random-normal placement. % To start, the user is asked to define the number of groups and the type % of random numbers, uniform (u) or normally distributed (n), to use % within the groups. The number of groups is calculated from the number per % group (npg) for use below. ng = 100 / npg; N = 100; % Now, a check to make sure that each group can have the same number; i.e. % you cannot have six groups, since 6 does not divide evenly into 100, and % this will make the functions unhappy. if npg ~= round(npg) error('100 must be divisible by the no. per group!'); end % Now, the center points for the groups are generated. C = evenGroupCenters2d(ng); % Next, for each center point p, random points are generated within a circle % at (0,0) by the circlefish function, and adjusted out to the center point. 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. if randtype == 'u' CPTS = circleFish2d(npg); % Generate the group. elseif randtype == 'n' CPTS = randPtsNormal2d(npg); end CPTS(:,2) = CPTS(:,2) + V(1,1); % Adjust the x-coordinates. CPTS(:,3) = CPTS(:,3) + V(1,2); % Adjust the y-coordinates. CPTS(:,4) = p; % Attach a group number to each point, % so that groups may be identified. CPTSN = [CPTSN; CPTS]; % Build the matrix. end % Close the loop. CPTSN(:,1) = [1:N]'; GPTS = CPTSN; % Final product is labelled GPTS. % plot(GPTS(:,2),GPTS(:,3),'.') % Plot, for visual check; should be % axis([-60,60,-60,60]) % killed in final version.