Create random numbers inside a specific plane in xy plane
Show older comments
Hello everyone!
I am trying to generate some samples. These samples are evenly distributed in rectangular regions of R^2.
To be more specific I want to generate 400 samples in the parallelogram [2,8] x [1,2]
and 100 (different) samples in the parallelogram [ 6 , 8 ] × [ 2.5 , 5.5 ].
Finally I want to plot them in the xy plane.
I have spent hours of searching. Any help appreciated.
Thanks in advance !
Answers (2)
I don't understand how you are specifying your parallelograms. However, one way is to use ndgrid and then apply a shear:
[X,Y]=ndgrid(1:10);
X=X(:);
Y=Y(:)+0.5*X(:);
scatter(X,Y)
2 Comments
NEFELI GAROUFALI
on 28 Jun 2022
Yes, the same idea applies with rand
N=40;
[X,Y]=deal(rand(N), rand(N));
X=X(:);
Y=Y(:)+0.5*X(:);
scatter(X,Y)
rng("default")
x = [2;8];
y = [1;2];
R = rand(2,400)
S = [x(1);y(1)]+[[x(2)-x(1);0],[0;y(2)-y(1)]]*R
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
