From: radar on
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
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
thanks very much!

I thought I had tried a similar datenum iteration trick, so I must have given up too easily