MATLAB: How to create 3 random numbers in a circle with 3 different radiuses.

random number generator

I have to make 15 circles with each circle there are 3 random numbers that can will find in a 3 different radiuses??

Best Answer

  • Let R be a row vector of the three different radii. Then assuming that the random points have to be randomly inside that radius rather than at the radius exactly,
    rr = sqrt(rand(15,3)) .* R
    rt = rand(15,3)* 2*pi;
    [xoff, yoff] = pol2cart(rt, rr) ;
    now xoff and yoff will be 15 x 3, one row for each circle and the different columns for the different radii. They are the x and y offset relative to the center of the respective circles. You need to add the coordinates of the center of the circle to those.
    X = repmat(CentX(:), 1,3) + xoff
    similar for y