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 日

0 投票

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 件のコメント

davit petraasya
davit petraasya 2016 年 2 月 9 日
編集済み: davit petraasya 2016 年 2 月 9 日
Thanks Guillaume for the response. It is very close what I want to do. Actually I gave my question a little simple way.Could you please help me to my question again if you can?
So I have box borders X(1.7,7.7) and Y(42.3,47.3). I should choose random 18 small square boxes in the box. The with or length(actually width=length as it is square) of the small boxes would be from 0.1-2.2. The small boxes must be in the big box.
Thank you for your time.
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 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by