Generate column of random numbers that change slowly from row to row

4 visualizaciones (últimos 30 días)
I have basic code here that generates pseudorandom numbers from 0.2 to 0.8, 200 times.
T = 200;
prob = 0.2+0.8*rand(T,2); % 200x2 double of random numbers
I want to adapt this code to constrain the number generated somehow so that they do not deviate much from row to row. In other words, I want each number to gradually change as the rows continue. For example:
0.5239 0.7115
0.4636 0.7117
0.5127 0.7214
0.4790 0.6998
0.4762 0.6944
0.5071 0.6777
As opposed to currently where the changes from row to row are quite dramatic:
0.945807614921516 0.378485320607502
0.414444310039899 0.894364308664596
0.375143552399965 0.609302224704160
0.745332926293388 0.429105784162042
0.781003750944333 0.991048513739670
Any help is much appreciated, thank you!

Respuesta aceptada

Jeff Miller
Jeff Miller el 3 de Dic. de 2019
You might generate the random points as you have but then smooth them with the smooth or filter function, e.g.,
sprob = zeros(size(prob));
sprob(:,1) = smooth(prob(:,1));
sprob(:,2) = smooth(prob(:,2));
The sprob values will change more slowly, so perhaps those would give you what you want.

Más respuestas (2)

Raunak Gupta
Raunak Gupta el 3 de Dic. de 2019
Hi,
You may try to sort each column (in any order) separately and then join them as then the difference between each row will be minimum. Also, the rand generate uniformly distributed random numbers that is if large amount of random numbers are generated those will not have much difference when arrange in ascending or descending fashion.

Walter Roberson
Walter Roberson el 3 de Dic. de 2019
Use randn() instead of rand, use non-zero starting point (possibly chosen by rand()) and a positive mean (probably), and multiply the randn() by a scaling factor, and then cumsum()

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by