filling the gaps in the sequence of dates

2 ビュー (過去 30 日間)
antonet
antonet 2012 年 8 月 7 日
EDITED
Dear all,
I have A={
'kl' '10/08' [4.4840] [4.1101] [ 0]
'kl' '01/09' [4.4840] [4.1101] [ 0]
'kl' '02/09' [4.1101] [4.0311] [ 0]
'kl' '03/09' [4.0311] [3.9358] [ 0]
'kl' '04/09' [3.9358] [3.9739] [ 0]
'kl' '05/09' [3.9739] [3.9267] [ 0]
'kl' '07/09' [3.9059] [3.8655] [ 0]
'kl' '08/09' [3.8655] [3.8889] [3.7498]
'kl' '10/09' [3.7498] [3.8857] [ 0]
'kl' '11/09' [3.8857] [4.4207] [4.1647]
'kl' '01/10' [4.1647] [3.7704] [ 0]
'kl' '02/10' [3.7495] [3.7085] [ 0]
'kl' '04/10' [3.7085] [3.6800] [ 0]
'kl' '05/10' [3.6800] [3.7364] [3.7867]
'kl' '07/10' [3.7867] [3.7860] [ 0]
'kl' '08/10' [3.7860] [3.7888] [3.6435]
'kl' '10/10' [3.6435] [3.6149] [ 0]
'kl' '11/10' [4.2260] [3.8786] [ 0]
'kl' '01/11' [3.8786] [3.5946] [3.5765]
'kl' '02/11' [3.5765] [3.5946] [ 0]
'kl' '04/11' [3.5946] [3.6493] [ 0]
'kl' '05/11' [3.6493] [3.5918] [3.6956]
'kl' '07/11' [3.6956] [3.7282] [ 0]
'kl' '08/11' [3.7326] [3.6308] [ 0]
'kl' '10/11' [3.6308] [3.6523] [4.1421]
'kl' '11/11' [4.1421] [2.0710] [ 0]}
The second column is month/year. Is it possible to fill the gaps in the sequence of the dates and for this additional row to set the rest of the elements equal to NaN? Specifically, the first date changes and is not fixed. Also the last date must be the date of the last row.
That is;
A={
'kl' '10/08' [4.4840] [4.1101] [ 0
[NaN] '11/08' [NaN] [NaN] [NaN]
[NaN] '12/08' [NaN] [NaN] [NaN]
'kl' '01/09' [4.4840] [4.1101] [ 0]
'kl' '02/09' [4.1101] [4.0311] [ 0]
'kl' '03/09' [4.0311] [3.9358] [ 0]
'kl' '04/09' [3.9358] [3.9739] [ 0]
'kl' '05/09' [3.9739] [3.9267] [ 0]
[NaN] '06/09' [NaN] [NaN] [NaN]
'kl' '07/09' [3.9059] [3.8655] [ 0]
'kl' '08/09' [3.8655] [3.8889] [3.7498]
[NaN] '09/09' [NaN] [NaN] [NaN]
'kl' '10/09' [3.7498] [3.8857] [ 0]
'kl' '11/09' [3.8857] [4.4207] [4.1647]
[NaN] '12/09' [NaN] [NaN] [NaN]
And so forth . the last date must be
'11/11'
Just to mentionthat the last date may change and is not fixed as it happens with the first date. SO the "last date" can be any date and the code must not create any new dates after the "last date"
Thanks in advance

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 8 月 7 日
編集済み: Andrei Bobrov 2012 年 8 月 8 日
d0 = datenum(A(:,1),'mm/yy');
k = diff(year(d0([1,end]))) + 1;
d1 = datenum(2009,(1:k*12)',1);
out = num2cell(nan(numel(d1),size(A,2)));
out(:,1) = cellstr(datestr(d1,'mm/yy'));
out(ismember(d1,d0),2:end) = A(:,2:end);
EDIT
[y,m] = datevec(A([1,end],2),'mm/yy');
mths = diff(y)*12+diff(m);
N = cellstr(datestr(datenum(y(1),(m(1)+(0:mths))',1),'mm/yy'));
out = repmat({nan},numel(N),size(A,2));
out(ismember(N,A(:,2)),[1,3:end]) = A(:,[1,3:end]);
out(:,2) = N;
  5 件のコメント
antonet
antonet 2012 年 8 月 8 日
編集済み: antonet 2012 年 8 月 8 日
ok Azzi. I left only the relevant parts. I hope this helps and sorry for causing any inconvenience. I am just struggling to find the solution and I can't. If you want please help me
thank you
antonet
antonet 2012 年 8 月 8 日
Thanks Andrei!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by