How can I select a random numbers from an array in a repeating way?

조회 수: 2 (최근 30일)
Tania Islam
Tania Islam 2019년 11월 4일
댓글: Tania Islam 2019년 11월 4일
I have an array name time with 1 row and 1000 columns.
time=[5,6,7,2,8,1,3,9......]
I want to call randomly any values from that array. Following is my working algorithm.
time2 = any random values from time
time3 = any random values from time
time4 = (time2 + time3)/2
time5 = any random value from time
common time = 5;
time6 = common time - time5;
time7 = time4 + time6
I have to store the values of time7 and have to repeat this process for 1000 times. That I can get the 1000 times time7 values.
How can I do this in MATLAB?

채택된 답변

Bhaskar R
Bhaskar R 2019년 11월 4일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by