Creating an array of datenum(s)
5 views (last 30 days)
Show older comments
I'm new to datenum, datestr etc and I have a relatively simple question:
I know the original start date of my monthly data:
>> datenum([1871 1 15 0 0 0])
ans =
683384
and that I have 141 months total. How do I populate an array so that I can match it to another time vector that I've already created? (see below)
Essentially I'm looking for:
time_index=ismember(first_tv,second_tv);
>> tv
tv =
1999 3 15 0 0 0
1999 4 15 0 0 0
1999 5 15 0 0 0
1999 6 15 0 0 0
1999 7 15 0 0 0
1999 8 15 0 0 0
1999 9 15 0 0 0
1999 10 15 0 0 0
1999 11 15 0 0 0
1999 12 15 0 0 0
2000 1 15 0 0 0
2000 2 15 0 0 0
2000 3 15 0 0 0
2000 4 15 0 0 0
2000 5 15 0 0 0
2000 6 15 0 0 0
2000 7 15 0 0 0
2000 8 15 0 0 0
2000 9 15 0 0 0
2000 10 15 0 0 0
2000 11 15 0 0 0
2000 12 15 0 0 0
2001 1 15 0 0 0
2001 2 15 0 0 0
2001 3 15 0 0 0
2001 4 15 0 0 0
2001 5 15 0 0 0
2001 6 15 0 0 0
2001 7 15 0 0 0
2001 8 15 0 0 0
2001 9 15 0 0 0
2001 10 15 0 0 0
2001 11 15 0 0 0
2001 12 15 0 0 0
2002 1 15 0 0 0
2002 2 15 0 0 0
2002 3 15 0 0 0
2002 4 15 0 0 0
2002 5 15 0 0 0
2002 6 15 0 0 0
2002 7 15 0 0 0
2002 8 15 0 0 0
2002 9 15 0 0 0
2002 10 15 0 0 0
2002 11 15 0 0 0
2002 12 15 0 0 0
2003 1 15 0 0 0
2003 2 15 0 0 0
2003 3 15 0 0 0
2003 4 15 0 0 0
2003 5 15 0 0 0
2003 6 15 0 0 0
2003 7 15 0 0 0
2003 8 15 0 0 0
%and have turned my time vector into a datenum:
second_tv =
730194
730225
730255
730286
730316
730347
730378
730408
730439
730469
730500
730531
730560
730591
730621
730652
730682
730713
730744
730774
730805
730835
730866
730897
730925
730956
730986
731017
731047
731078
731109
731139
731170
731200
731231
731262
731290
731321
731351
731382
731412
731443
731474
731504
731535
731565
731596
731627
731655
731686
731716
731747
731777
731808
Thanks!
2 Comments
Accepted Answer
More Answers (2)
Matt Kindig
on 1 Nov 2013
Edited: Matt Kindig
on 1 Nov 2013
If I understand you correctly, this should do it:
[~, time_index] = ismember( datenum(tv), second_tv);
J.C.
on 8 Nov 2013
Why not just use a loop?
t(1:141, 1) = zeros;
t(1) = datenum([1871 1 15 0 0 0]);
for i = 2:141
t(i) = addtodate(t(i-1), 1, 'month');
end
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!