Random points moving from boundary
2 次查看(过去 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!
0 个评论
采纳的回答
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
3 个评论
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'})
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!