Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 生成一个随机数数组,使得索引越高的数越大_Arrays_Matlab_Random - Fatal编程技术网

Arrays 生成一个随机数数组,使得索引越高的数越大

Arrays 生成一个随机数数组,使得索引越高的数越大,arrays,matlab,random,Arrays,Matlab,Random,我试图生成一个随机数数组,这样较高索引处的数应该大于较低索引处的数 例如,这样的数组: array = [1.5 1.7 2.4 5.6 8.5 8.9 9.2 9.5 10.2 11.3] 我可以使用以下方法进行此操作: array(1:10) = 0; % Pre-allocation array(1) = abs(randn); % Generating a +ve rand no. for k=2:10 array(k) = abs(randn)

我试图生成一个随机数数组,这样较高索引处的数应该大于较低索引处的数

例如,这样的数组:

array = [1.5  1.7  2.4  5.6  8.5  8.9  9.2  9.5  10.2  11.3]
我可以使用以下方法进行此操作:

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
我正在寻找更好的(和/或矢量化)方法

myarray=sort(rand(1,10))

我想可以

编辑:

虽然你的问题没有提到,但从你的例子来看,你想要正数

所以
sort(abs(rand(1,10)))


你想怎么做就怎么做。

为什么不直接使用阵列?没想到会这么简单!谢谢