Random uniform data points

2 ビュー (過去 30 日間)
Simon De Gheselle
Simon De Gheselle 2020 年 3 月 19 日
回答済み: Moreno, M. 2022 年 3 月 20 日
I am evaluating a positioning technique in a 3D environment (5m x 5m x 3m), is it possible to generate random unform distributed 3D coordiantes?
I am currently using the following code snippet:
a = -(width_dimension/2);
b = width_dimension/2;
rand_x = width_dimension.*rand(number_of_test_samples,1) + a;
a = -(length_dimension/2);
b = length_dimension/2;
rand_y = length_dimension.*rand(number_of_test_samples,1) + a;
a = 0;
b = height_dimension;
rand_z = height_dimension.*rand(number_of_test_samples,1) + a;
  1 件のコメント
Adam Danz
Adam Danz 2020 年 3 月 19 日
編集済み: Adam Danz 2020 年 3 月 19 日
rand() returns random numbers from a uniform distribution bounded by [0,1].
Are you asking how to return a 3D array of random numbers?
d = rand(10,5,4); % returns 10x5x4 array of randos

サインインしてコメントする。

回答 (2 件)

Ameer Hamza
Ameer Hamza 2020 年 3 月 19 日
編集済み: Ameer Hamza 2020 年 3 月 19 日
You can generate the coordinates with a single call to rand()
width_dimension = 5;
length_dimension = 5;
height_dimension = 3;
number_of_test_samples = 1000;
rand_values = rand(number_of_test_samples, 3) - 0.5;
rand_values = rand_values.*[width_dimension length_dimension height_dimension];
First colums is x-coordinate. Second and third columns are y and z-coordinates respectively.

Moreno, M.
Moreno, M. 2022 年 3 月 20 日
https://uk.mathworks.com/matlabcentral/fileexchange/108374-uniformly-distributed-points

Community Treasure Hunt

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

Start Hunting!

Translated by