필터 지우기
필터 지우기

how to generate random time format data in MATLAB?

조회 수: 17 (최근 30일)
saharsahar
saharsahar 2013년 7월 5일
Hi all, I am wondering how to generate random time format data (or series) in MATLAB between a range of time ? such as 12:00:23 , ......?
Thanks

채택된 답변

the cyclist
the cyclist 2013년 7월 5일
Here's one way:
% Generate a random time (down to granularity of seconds)
% Parameters
NUMBER_RANDOM_TIMES = 100;
SECONDS_PER_DAY = 24*60*60;
START_DATE = '2013-01-01';
END_DATE = '2013-06-30';
% Algorithm
startDateNum = datenum(START_DATE,'yyyy-mm-dd');
endDateNum = datenum(END_DATE, 'yyyy-mm-dd');
dayRange = endDateNum - startDateNum;
secondsRange = SECONDS_PER_DAY*dayRange;
randomNumberOfSeconds = randi(secondsRange,NUMBER_RANDOM_TIMES,1);
randomDatenums = startDateNum + randomNumberOfSeconds/SECONDS_PER_DAY;
randomDates = datestr(randomDatenums);
  댓글 수: 2
saharsahar
saharsahar 2013년 7월 5일
Well, Thanks for your response,actually I am looking for generate random times between , lets say, 20:00:00 on 4/5/2013 and 05:00:00 on 5/5/2013. Actually I am not sure how I can address your algorithm in this issue?
Thanks for any help...
the cyclist
the cyclist 2013년 7월 5일
Change these lines:
START_DATE = '2013-04-05 20:00:00';
END_DATE = '2013-05-05 05:00:00';
startDateNum = datenum(START_DATE,'yyyy-mm-dd HH:MM:SS');
endDateNum = datenum(END_DATE, 'yyyy-mm-dd HH:MM:SS');

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by