İmplementing a Pause button

조회 수: 11 (최근 30일)
Franck paulin Ludovig pehn Mayo
Franck paulin Ludovig pehn Mayo 2022년 5월 17일
답변: Voss 2022년 5월 18일
hello everyoneş
İ have a start push button whicjh is basically recording the position, date and 'time' when the mouse is on pointer/mouse cursor is on the canvas.
İt is on this format
ex:(X, Y, time) = (237, 393, 12-May-2022 13:03:55, 2&1!, AA4)
(X, Y, time) = (505, 437, 12-May-2022 13:03:55, 2&1!, AA4)
(X, Y, time) = (616, 452, 12-May-2022 13:03:56, 2&1!, AA4)
İ am more interested in the seconds. İs there anyway seconds can just be recorded?
İ would like to buid a Pause pushbutton that will pause just the 'time' to move (because the experiment is long so sometimes the user will need a break). İ dont have any idea on how to do it. Also what could be challenging is that i dont know how i could handle the 'Enable','off' and 'Enable','on' of the Start and stop callbacks
.
% --- Executes on button press in Start_button.
function Start_button_Callback(hObject, eventdata, handles)
% hObject handle to Start_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.fileID = fopen('Start_Stop.txt','w');
handles.t = timer('ExecutionMode', 'fixedRate', ...
'Period', 0.5, ...
'TasksToExecute', Inf, ...
'TimerFcn', {@timerCallback, handles.finger});
start(handles.t);
set(handles.Start_button,'Enable','off'); % -> Disable the button
guidata(hObject,handles);% -----> do this to save the updated handles object
function timerCallback(~,~,f)
handles = guidata(f);
%fprintf(fileID,'(X, Y, time) = (%g, %g, %s)\n', get(0, 'PointerLocation'), datetime('now'));
fprintf(handles.fileID,'(X, Y, time) = (%g, %g, %s, %s, %s)\n', get(0, 'PointerLocation'), datetime('now'), ...
handles.amplitude{handles.exp_counter},handles.f_df{handles.exp_counter});
%fprintf('calling timer callback\n');
function Stop_button_Callback(hObject, eventdata, handles)
% hObject handle to Stop_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
stop(handles.t) %whenever we want to stop.
fclose(handles.fileID);
set(handles.Start_button,'Enable','on'); % -> Enable the button
guidata(hObject,handles);
% --- Executes on button press in pause_button.
function pause_button_Callback(hObject, eventdata, handles)
% hObject handle to Stop_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
guidata(hObject,handles);

채택된 답변

Voss
Voss 2022년 5월 18일
"İs there anyway seconds can just be recorded?"
second(datetime('now'))
ans = 24.7870
pause(2)
second(datetime('now'))
ans = 26.9439
Using that in your code where you write to file:
fprintf(handles.fileID,'(X, Y, time) = (%g, %g, %f, %s, %s)\n', get(0, 'PointerLocation'), second(datetime('now')), ...
handles.amplitude{handles.exp_counter},handles.f_df{handles.exp_counter});
Regarding the pause button, maybe this callback is a start:
function pause_button_Callback(hObject, eventdata, handles)
if strcmp(get(handles.t,'Running'),'on')
stop(handles.t);
else
start(handles.t);
end
The idea is that the pause button pauses and also un-pauses the experiment. (The start button remains disabled while the experiment is paused.)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by