lundi 26 septembre 2016

Generating an array of random numbers such that the numbers at the higher indexes are greater

I am trying to generate an array of random numbers such that the numbers at the higher indexes should be greater than the numbers at the lower indexes.

For example, an array like this:

array = [1.5  1.7  2.4  5.6  8.5  8.9  9.2  9.5  10.2  11.3]

I can do this using:

array(1:10) = 0;       % Pre-allocation
array(1) = abs(randn); % Generating a +ve rand no.
for k=2:10
    array(k) = abs(randn) + array(k-1);  % adding a +ve rand no. to the previous value 
end

I am looking for a better (and/or vectorized) way!




Aucun commentaire:

Enregistrer un commentaire