Calculating combinations of dates

2 ビュー (過去 30 日間)
antonet
antonet 2012 年 6 月 30 日
Dear all,
I have the following cell vector of dates
jji= '23/11/08'
'28/12/08'
'25/01/09'
that corresponds to the cell vector of values
values
[0.5637]
[0.6034]
[0.5943]
[0.4567 ]
and I want to create the following new vector of values
(23*0.5637+7*0.6034)/30
(28*0.6034+3*0.5943)/31
(25*5943+6*0.4567)/31
where in the first row of this vector the numerator (23*0.5637+7*0.6034) is the sum of two products.
In the first product which is 23*0.5637 the number 23 is actually the first two digits from '23/11/08'
In the second product which is 7*0.6034 the number 7 is actually the distance in days between '23/11/08' and the end date of that month, that is the difference
'23/11/08-30/11/08
The denominator in the first row (30) is the total number of days for month November 2008
Similar analysis holds for the rest of the rows.
In my case I have a huge vector of dates and values. is there any way to construct the new vector of values?
My proposal is this:
jji={ '23/11/08'
'28/12/08'
'25/01/09'
};
values ={
0.5637
0.6034
0.5943
0.4567 };
for i = 1:length(jji)
jjii{i,1} = jji{i,1}(1:2);
end
that produces
jjii =
'23'
'28'
'25'
TO find the end dates of each month i use
[Y, M] = datevec(jji,'dd/mm/yy'); enddates = datestr(datenum(Y,M+1,1)-1,'dd/mm/yy')
and I obtain
30/11/08 31/12/08 31/01/09
but then I need to calculate the differences between the jji and "endndates"
Any suggestions?
thank you
  1 件のコメント
antonet
antonet 2012 年 6 月 30 日
I think I found how to calculate this difference
datenum(enddates,'dd/mm/yy') - datenum(jji,'dd/mm/yy')
But is there a better approach?
THanks

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 6 月 30 日
編集済み: Andrei Bobrov 2012 年 6 月 30 日
EDIT
[Y M D] = datevec(jji,'dd/mm/yyyy');
ED = eomday(Y, M);
v = cell2mat(values);
n = numel(v);
out = sum([D, ED-D].*v(hankel(1:n-1,n+[-1 0])),2)./ED;
  5 件のコメント
Andrei Bobrov
Andrei Bobrov 2012 年 6 月 30 日
Sorry! I am use values as double array:
values =[0.5637
0.6034
0.5943
0.4567];
See EDIT
antonet
antonet 2012 年 6 月 30 日
Thanks Andrei.
I would like to ask what numel does in : n= numel(values);
Could we alternative have
kk=size(values);
n=kk(1,1);
thank you

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDownloads についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by