Hi Xiong,
If you want the hour to include time while the protocol is paused, you could also use:
% Just before the main loop
startTime = now*100000;
...
% Inside the main loop
currentTime = now*100000;
% At the bottom of the main loop
if (currentTime - startTime >= 3600)
% End the protocol
end
MATLAB's now() function returns the current time (multiply by 100000 to get seconds, 3600 seconds per hour).
If the idea is to exclude time while the protocol is paused, you can create a local variable, you can add the trial duration of each trial, and compare the sum to 3600:
% Just before the main loop
totalTrialTime = 0;
...
% After each call to AddTrialEvents()
totalTrialTime = totalTrialTime + (BpodSystem.Data.TrialEndTimestamp(currentTrial) - BpodSystem.Data.TrialStartTimestamp(currentTrial));
% At the bottom of the main loop
if (totalTrialTime >= 3600)
% End the protocol
end
This works because pauses occur in the inter-trial interval. Please note that your sum will not include the ~7-10ms of dead-time between trials (assuming that you're not using TrialManager).
I hope this helps!
-Josh