【问题标题】:How can I select a random numbers from an array in matlab in a repeating way?如何以重复的方式从matlab中的数组中选择一个随机数?
【发布时间】:2019-11-04 07:54:30
【问题描述】:

我有一个 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 中做到这一点?

【问题讨论】:

  • 什么是 time1 ? .你没有提到它
  • 对不起,时间到了 4

标签: arrays matlab random


【解决方案1】:
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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-27
    • 2013-07-17
    • 1970-01-01
    • 2019-02-26
    • 2012-11-16
    • 2021-07-06
    • 2011-11-13
    相关资源
    最近更新 更多