Creating an array of datenum(s)

6 views (last 30 days)
Kate
Kate on 1 Nov 2013
Answered: Kate on 8 Nov 2013
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
Cedric
Cedric on 1 Nov 2013
Edited: Cedric on 1 Nov 2013
What is the purpose ultimately? What do you want to do with the match?
Kate
Kate on 8 Nov 2013
Cedric, what I'm looking to do it pull (in this case reanalysis meteorological drivers which span 140 yrs) which match the time period for my flux data (which varies by site, but in this example lasts ~5 years (give or take a few months on either end)).
Essentially I'm trying to get to:
time_index=ismember(met_tv,flux_tv);
%pull grid location of fluxnet data
[i,j]=findGridcell(site, .5); %this works fine
metdriver=metdriver(i, j, time_index); %this is what I'm stuck on b/c of time vector issues
sensitivity=flux_data/metdriver; %end-product that I need
Does that make sense?

Sign in to comment.

Accepted Answer

Kate
Kate on 8 Nov 2013
FYI/for future reference:
>> ((datenum([repmat(1871,1692,1) [1:1692]' repmat([15 0 0 0],1692,1)])));

More Answers (2)

Matt Kindig
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);
  1 Comment
Kate
Kate on 1 Nov 2013
So I actually don't have my first tv yet, I need to create it. It's a monthly value that starts in 1871 and goes to present. Once I create it I can find matches between my first tv and my second tv. Does that make sense?

Sign in to comment.


J.C.
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
  1 Comment
Kate
Kate on 8 Nov 2013
You're right JC, I was making this too complicated. I ended up doing:
>> ((datenum([repmat(1871,1692,1) [1:1692]' repmat([15 0 0 0],1692,1)])));
Which does the same thing without a loop.

Sign in to comment.

Categories

Find more on Dates and Time in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!