MATLAB: How to vectorize the following code

vectorization

Could anyone explain the steps?
DelayStep = 60;%in seconds
MaxStep = 86400;
for j=dStart:dEnd
currDay = datevec(j);
for k=0:DelayStep:MaxStep
hms = [0 0 0 fix(mod(k, [0, 3600, 60]) ./ [3600, 60, 1])];
UTCTimetoCalculate = datestr(hms+currDay);
end
end

Best Answer

You can replace the inner ‘k’ loop with:
currDay = datevec(j);
hms = bsxfun(@plus, currDay, zeros(1440,6));
hms(:,5) = 1:1440;
TCTimetoCalculate = datestr(datenum(hms));
since you are actually incrementing every minute (with 1440 minutes/day)|.