フィルターのクリア

Random points moving from boundary

1 回表示 (過去 30 日間)
davit petraasya
davit petraasya 2016 年 2 月 9 日
コメント済み: davit petraasya 2016 年 2 月 10 日
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 件)

カテゴリ

Help Center および File ExchangeHypothesis Tests についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by