フィルターのクリア

How to generate random time series with specified max-min time intervals?

3 ビュー (過去 30 日間)
Chris
Chris 2013 年 12 月 6 日
コメント済み: Jos (10584) 2013 年 12 月 6 日
Hello,
I'd like to generate a time vector with random ascending values in which the interval between two adjacent values would be given by me, i.e. something like:
0 - min number in vector;
60 - max number in vector
0.5 - min interval between adjacent values
2 - max interval between adjacent values
Which would give something like : [0 0.7 1.8 2.4 ...... 59.1 60]

採用された回答

Jos (10584)
Jos (10584) 2013 年 12 月 6 日
Some improvements over Andrei's code
minV = 0
maxV = 60
minDiff = 0.5
maxDiff = 2.0 ;
N = ceil((maxV-minV) / minDiff) ; % ensures there are enough numbers in d
d = minDiff + (maxDiff-minDiff)*rand(N,1);
d2 = [0;cumsum(d)];
out = [ d2(d2 < (maxV - minDiff)) ; maxV ];
  2 件のコメント
Andrei Bobrov
Andrei Bobrov 2013 年 12 月 6 日
+1
Jos (10584)
Jos (10584) 2013 年 12 月 6 日
I have no time to disproof it right now, but I have the feeling that it might happen that out(end)-out(end-1) is larger than maxDiff.
I suggest you check against that condition and run the engine again when necessary ..

サインインしてコメントする。

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2013 年 12 月 6 日
編集済み: Andrei Bobrov 2013 年 12 月 6 日
One way
d = .5 + 1.5*rand(70,1);
d2 = [0;cumsum(d)];
out = [d2(d2 < 60 - .5);60];
  3 件のコメント
Jos (10584)
Jos (10584) 2013 年 12 月 6 日
A quick fix would be out = [d2(d2 < (60-0.5) ; 60] ; but this would abort true randomness, which might or might not be an important issue here ...
Andrei Bobrov
Andrei Bobrov 2013 年 12 月 6 日
編集済み: Andrei Bobrov 2013 年 12 月 6 日
Hi Jos! Thanks for your comments. Corrected.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by