İmplementing a Pause button
9 ビュー (過去 30 日間)
古いコメントを表示
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);
0 件のコメント
採用された回答
Voss
2022 年 5 月 18 日
"İs there anyway seconds can just be recorded?"
second(datetime('now'))
pause(2)
second(datetime('now'))
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!