我在Matlab中有3个不同的字符串数组,它们包含不同的出发时间。
一个阵列适用于'07:00','07:10'的离场..... 下一个阵列适用于'08:00','08:10'的离场... 第三个是'09:00','09:10'离开。
现在我想创建一个新的矩阵/数组,从这3个数组中取出随机值并将其放入一个包含1000个输入的新矩阵中,我该怎么做?
代码:
SevenOclock = ["07:00","07:05","07:10","07:15","07:20","07:25","07:30","07:35","07:40","07:45","07:50","07:55"]'
EightOclock = ["08:00","08:05","08:10","08:15","08:20","08:25","08:30","08:35","08:40","08:45","08:50","08:55"]'
NineOclock = ["09:00","09:05","09:10","09:15","09:20","09:25","09:30","09:35","09:40","09:45","09:50","09:55"]'
randomDeparture = rand(SevenOclock; EightOclock; NineOclock) %NOT WORKING!! HELP
有人可以帮助我吗?
答案 0 :(得分:2)
您正在寻找randsample
,随机抽样。整理的代码看起来像这样:
minutes = ["00";"05";"10";"15";"20";"25";"30";"35";"40";"45";"50";"55"];
SevenOclock = "07:" + minutes;
EightOclock = "08:" + minutes;
NineOclock = "09:" + minutes;
allDepartures=[SevenOclock;EightOclock;NineOclock];
randomDeparture = randsample(allDepartures,1000,true);