Random points moving from boundary
1 view (last 30 days)
Show older comments
davit petraasya
on 9 Feb 2016
Commented: davit petraasya
on 10 Feb 2016
Hello
I have square surface(300kmto300km) and I am picking random points(20points) in the surface. My task is my random points should not be close than 10 km to square borders. So how I can give command that if my random point less than 10 km close to square borders choose another point.
Thanks a lot!
0 Comments
Accepted Answer
Guillaume
on 9 Feb 2016
Rather than checking if a random point is outside your allowed range and retrying, you'd generate random points within your allowed range to start with:
allowedrange = [10 290];
numpoints = 20;
xy = rand([2, numpoints) * diff(allowedrange) + allowedrange(1) %generate numpoints pairs
3 Comments
Guillaume
on 9 Feb 2016
This should work:
sizerange = [0.1 2.2];
boxsize = rand(18, 1) * diff(sizerange) + sizerange(1);
topleft = [1.7 42.3]
bottomright = [7.7 47.3]
boxxy = cell2mat(arrayfun(@(sz) rand(1, 2) .* (bottomright - topleft - sz) + topleft, boxsize, 'UniformOutput', false))
array2table([boxxy boxsize], 'VariableNames', {'X', 'Y', 'Size'})
More Answers (0)
See Also
Categories
Find more on Hypothesis Tests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!