Create random numbers inside a specific plane in xy plane

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

@Matt J Thank you very much for your response.
The first parallelogram has edges the points (2, 1) (8, 1) (2, 2) (8, 2)
And the second parallelogram has edges the points (6, 2.5) (8, 2.5) (6, 5.5) (8, 5.5)
Also the samples must be random. Like a "cluster" perhaps. From the searching I did I think this should be done maybe with function rand or something like this.
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)

Sign in to comment.

rng("default")
x = [2;8];
y = [1;2];
R = rand(2,400)
R = 2×400
0.8147 0.1270 0.6324 0.2785 0.9575 0.1576 0.9572 0.8003 0.4218 0.7922 0.6557 0.8491 0.6787 0.7431 0.6555 0.7060 0.2769 0.0971 0.6948 0.9502 0.4387 0.7655 0.1869 0.4456 0.7094 0.2760 0.6551 0.1190 0.9597 0.5853 0.9058 0.9134 0.0975 0.5469 0.9649 0.9706 0.4854 0.1419 0.9157 0.9595 0.0357 0.9340 0.7577 0.3922 0.1712 0.0318 0.0462 0.8235 0.3171 0.0344 0.3816 0.7952 0.4898 0.6463 0.7547 0.6797 0.1626 0.4984 0.3404 0.2238
S = [x(1);y(1)]+[[x(2)-x(1);0],[0;y(2)-y(1)]]*R
S = 2×400
6.8883 2.7619 5.7942 3.6710 7.7450 2.9457 7.7430 6.8017 4.5306 6.7532 5.9344 7.0948 6.0724 6.4588 5.9329 6.2363 3.6615 2.5828 6.1690 7.7013 4.6325 6.5931 3.1212 4.6735 6.2562 3.6562 5.9306 2.7140 7.7585 5.5116 1.9058 1.9134 1.0975 1.5469 1.9649 1.9706 1.4854 1.1419 1.9157 1.9595 1.0357 1.9340 1.7577 1.3922 1.1712 1.0318 1.0462 1.8235 1.3171 1.0344 1.3816 1.7952 1.4898 1.6463 1.7547 1.6797 1.1626 1.4984 1.3404 1.2238

Categories

Find more on Random Number Generation in Help Center and File Exchange

Asked:

on 28 Jun 2022

Edited:

on 28 Jun 2022

Community Treasure Hunt

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

Start Hunting!