Random Point from meshgrid
古いコメントを表示
Hi everybody, I've a simple problem. I've to pick a certain number "N" of point from a meshgrid.
The constraints of the problem are the following:
- The number of point must be exactly N;
- The point must be part of the original set of point given by the meshgrid function;
- They must be random point from normal distribution (more dense at the center of the matrix and less dense near the boundaries of the matrix);
- The points need to be different each other;
Here is an example of the original grid that can be used as a starting point. The random point selected must belong to this grid and must satisfy the constraints stated above. Someone can help me? Thank you!
Nc = 20; Nr = 20; dx = 0.2; dy = 0.2;
x = -0.5*Nc*dx:dx:0.5*Nc*dx-dx; y = -0.5*Nr*dy:dy:0.5*Nr*dy-dy;
[X,Y] = meshgrid(x,y);
figure; plot(X,Y,'gs');
2 件のコメント
Matt J
2021 年 12 月 18 日
The 3rd requirement can't be reconciled with the others. A finite set cannot be normally distributed. A normal distribution is a continuous distribution.
Sargondjani
2021 年 12 月 18 日
編集済み: Sargondjani
2021 年 12 月 18 日
I don't know if there is out-of-the-box solution but if i had to program it myself i would do it as follows. And I am sure this is not the most advanced solution, but it would be a start for a beginner.
First try to make it work for 1D:
- make a mapping of continuous values between 0 and 1 to discrete values of x (ie. gridpoints). Use a distribution that you want. You can now draw a random number, between 0 and 1, and it will give you a gridpoint.
For 2D:
- basically do the 1D thing twice, once for x, once for y.
- Add a check whether a grid point was already selected before
- Repeat draws until you reach N points.
You may also have a look at the function randperm, but im not sure you can tweak the distribution.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

