필터 지우기
필터 지우기

What other option similar to tic/toc can be used for a time stamp program in GUI?

조회 수: 8 (최근 30일)
Hello, I have finally got my timestamp program working. I am using tic/toc to register the time that goes between selecting radiobuttons. The program runs fine. However, if I close matlab and I open it again it doesn't run anymore and a message shows that tic has to go before toc with no output arguments. I was wondering if you guys can help me fix this, any other alternatives?
Thanks!
function uibuttongroup1_SelectionChangedFcn(hObject, eventdata, handles)
% This is the radio button function that stores name, date and times of
% each selected button.
global filename;
fileID = fopen(filename,'at');
A = get(hObject,'String');
date = datetime('now','Format','MM/dd/yyyy');
dat = char(date);
time = datetime('now','Format','HH:mm:ss');
currentTime = char(time);
elapsedtime = datestr((toc/24/3600),'HH:MM:SS');
fprintf(fileID,'Event ends:\t %s\t %s\t Event duration:\t %s\t \n',dat,currentTime,elapsedtime);
fprintf(fileID,'%s\n',[]);
fprintf(fileID,'%s\t %s\t %s\n',A,dat,currentTime);
fclose(fileID);
persistent count
if isempty(count)
count = 0;
end
count = count + 1;
if count > 0
tic;
end

채택된 답변

Walter Roberson
Walter Roberson 2016년 1월 8일
The first time you run the routine, you have not yet done any tic . Elapsed time since the last button was pressed, but what of the case when no buttons have been pressed at all yet? What are you displaying the time relative to?
Perhaps you should be checking count before you toc, and not emitting the timing information if it is the first time you have run the routine.
Also, in the case where the routine has not been run yet, where count starts out empty, you set count to 0, but then you only tic if count > 0. That means that the first time you run the routine you do not tic either -- so the second time you run the routine there would still not have been a tic done yet even though it makes complete sense to talk about the time between the first and second button press. This suggests you should always tic even if count was empty.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dialog Boxes에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by