I am trying to combine these two buttons together, is it possible that just one pushbutton can do all the tasks?
function togglebutton1_Callback(hObject, eventdata, handles)% hObject handle to togglebutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of togglebutton1
set(handles.text1, 'String', '0.00'); persistent t; if get(hObject, 'Value') t = tic; %disp('timer started')
set(handles.togglebutton1,'String','Stop'); else elapsedtime = toc(t); save('data.mat','elapsedtime');% fprintf('time elapsed = %f', elapsedtime);
set(handles.text1, 'String', elapsedtime); set(handles.togglebutton1,'String','Start'); end% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)SET1P = getappdata(0,'evalue');% Read current text and convert it to a number.
currentCounterValue = str2double(get(handles.Counter, 'String'));nextValue = currentCounterValue + 1;if nextValue >= 32 nextValue = 1;end% Create a new string with the number being 1 more than the current number.
newString = sprintf('%d', int32(nextValue));% Send the new string to the text control.
set(handles.Counter, 'String', newString );set(handles.text2, 'String', SET1P{str2double(newString),1});
Best Answer