Random Point from meshgrid
Show older comments
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 Comments
Matt J
on 18 Dec 2021
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
on 18 Dec 2021
Edited: Sargondjani
on 18 Dec 2021
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.
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
