我如何以重复的方式从Matlab中的数组中选择一个随机数?

问题描述 投票:-1回答:1

我的数组名称时间为1行1000列。

时间= [5,6,7,2,8,1,3,9 ......]

我想从该数组中随机调用任何值。以下是我的工作算法。

time2 =来自时间的任何随机值

time3 =来自时间的任何随机值

time4 =(time2 + time3)/ 2

time5 =来自时间的任何随机值

普通时间= 5;

time6 =普通时间-time5;

time7 = time4 + time6

我必须存储time7的值,并且必须重复此过程1000次]。我可以得到1000倍的time7值。

如何在MATLAB中做到这一点?

arrays matlab random
1个回答
0
投票
len = length(time); % length of the vector
time7 = zeros(1,len) ;  % initilaize the vector time7 to store your time7
common_time = 5;
for iValue = 1:len
  % randi used to get a random value   
  time2 = time(randi([1, len], 1));
  time3 = time(randi([1, len], 1));
  time4 = (time2 + time3)/2;
  time5 = time(randi([1, len], 1));
  time6 = common_time - time5;
  time7(iValue) = time4 - time6;
end
© www.soinside.com 2019 - 2024. All rights reserved.