I have generated a figure of 4 x 4 area in matlab. Now I need to place more than 200 points(Actually moving device) on this area randomly but distributed evenly all over 4 x 4 area. I am using the following line to randomly generated the x and y co-ordinate to select the place for each of the different points.
a =200;
x_base = randi([1 5], 1, a);
b = rand([10 8], 1);
y_base = randi([3 7],1, a);
With the above code I can get only integer co-ordinates for x and y. Hence am not able to distribute the points evenly all over the area. This is because I am using randi function which generates integer only. I would like to know is there any way of generating floating point numbers randomly so that I can distribute the points more evenly?
I am looking for random floating point numbers between 1 to 20.
rand
Generates a number between 0 and 1.
rand(m,n) generates an m-by-n array of such numbers.
You want to select n random points in the 4x4 area from (0, 0) to (4, 4)?
unifinv(rand(n, 2), 0, 4)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With