フィルターのクリア

how to define specific indexes in a dataset?

2 ビュー (過去 30 日間)
aggelos
aggelos 2012 年 4 月 30 日
My aim is to define indexes for an in sample and an out of sample test of model fitting.
% define first and last date for calibration
cal_beg_date = '01-01-2010';
cal_end_date = '31-12-2010';
% define first and last date for out-of-sample forecast
for_beg_date = '01-01-2011';
for_end_date = '31-12-2011';
D = ds.Date(:,1);
% define respective indices and period lengths
cal_beg_i = find(D==eval(cal_beg_date));
cal_end_i = find(D==eval(cal_end_date));
for_beg_i = find(D==eval(for_beg_date));
for_end_i = find(D==eval(for_end_date));
cal_period = 1+cal_end_i-cal_beg_i;
for_period = 1+for_end_i-for_beg_i;
I use dataset to create my data in matlab and the adove code returns me an error. Could anyone tell me why a get an error. thanks in advance..

採用された回答

Peter Perkins
Peter Perkins 2012 年 4 月 30 日
aggelos, I think what you need is something like the datenum function, and not eval. As Per points out, eval'ing a date string is going to treat dashes as subtraction. You might create a new variable in your array,
ds.DateNum = datenum(ds.Date)
if you wanted to keep that around permanently, and then do something like
cal_beg_date = datenum('01-01-2010');
cal_end_date = datenum('31-12-2010');
calData = ds(cal_beg_date <= ds.DateNum & ds.DateNum <= cal_end_date,:)
Don't know what you're doing specifically, so the above may not be exactly what you want, but it should help.
  1 件のコメント
aggelos
aggelos 2012 年 5 月 1 日
thank you very much Peter.

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

その他の回答 (1 件)

per isakson
per isakson 2012 年 4 月 30 日
I guess this is not what you want?
>> eval('31-12-2010')
ans =
-1991

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by