Run something like this:
tic
loopTimer = toc
... % Loop start
while ((toc - loopTimer < 3); end % Make sure you actually hit 3 seconds
% Your function here...
loopTimer = toc
... % Loop end
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!