How to generate a date vactor of weekly intervals.

2 ビュー (過去 30 日間)
Jas Gil
Jas Gil 2012 年 4 月 30 日
Hello,
How can I generate a date vactor in which I know the start date let say end of last month (03/31/2012) and I know the frequency say weekly and I know how many rows I want let say 100 rows.

採用された回答

Patrick Kalita
Patrick Kalita 2012 年 4 月 30 日
Start by defining the beginning of the vector using datenum:
start = datenum(2012, 3, 31, 0, 0, 0)
Next, use datenum again to define the interval of 7 days:
offset = datenum(0, 0, 7, 0, 0, 0);
Finally, make a 100-element vector by multiplying the numbers 0 through 99 by the offset and adding them to the start date:
vec = start + (0:99)*offset;
You can verify the results by converting the serial date numbers in vec back to strings:
datestr(vec)

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2012 年 4 月 30 日
out = datenum(2012,3,31+ (0:7:7*99)',0,0,0);

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by