how to generate random time format data in MATLAB?
17 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Random Number Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!