Random points moving from boundary

1 次查看(过去 30 天)
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!

采纳的回答

Guillaume
Guillaume 2016-2-9
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
See the documentation on how to generate random numbers within a range.
  3 个评论
Guillaume
Guillaume 2016-2-9
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'})
davit petraasya
davit petraasya 2016-2-10
Thank you very much Guillaume. I appreciate very much the help you have given me!

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by