Prev: Easy Alising/Frequency
Next: Subscript Index error...
From: radar on 8 May 2010 14:42 Coming from a C++ environment using the Boost library, I'm disappointed to see even with the Financial Toolbox there appears to be no true data iteratior in matlab. For example, if I want to iterate over some dates and use other date related functions in that loop, I have to maintain a seperate variable just to call such functions as shown below. If someone knows a better way, please share it. Thanks. In this example, I have to maintain both k and iday where a true date iterator would not require two variables in a loop % set to first day of the month iday = datenum(yr, mn, 1); % for a given year and month, iterate over all days in that month for k = 1:day(eomdate(yr, mn)) % returns last day of the month if isbusday(iday) % if it's a bussiness day % do stuff here end; % increment day iday = addtodate(iday, 1, 'day'); end;
From: dpb on 8 May 2010 20:30 radar wrote: .... > In this example, > I have to maintain both k and iday > where a true date iterator would not require two variables in a loop > > % set to first day of the month > iday = datenum(yr, mn, 1); > > % for a given year and month, iterate over all days in that month > for k = 1:day(eomdate(yr, mn)) % returns last day of the month > if isbusday(iday) % if it's a bussiness day > % do stuff here > end; > % increment day > iday = addtodate(iday, 1, 'day'); > end; for k = iday:iday+day(eomdate(yr,mn)) % one way datenum(yr,mn,1):datenum(yr,mn+1,1)-1 % another --
From: radar on 8 May 2010 18:31 thanks very much! I thought I had tried a similar datenum iteration trick, so I must have given up too easily
|
Pages: 1 Prev: Easy Alising/Frequency Next: Subscript Index error... |