How to create a minus counter

조회 수: 4 (최근 30일)
Kwan Zhao Jie
Kwan Zhao Jie 2018년 3월 12일
댓글: Kwan Zhao Jie 2018년 3월 13일
on the code above i created a add counter
function patient_Callback(hObject, eventdata, handles)
counter2 = get(hObject, 'UserData') + 1;
set(hObject, 'UserData', counter2);
set(handles.Impt, 'String', sprintf('Number of Patients currently: %d\n', counter2));
but the minus code doesnt work
function patients_Callback(hObject, eventdata, handles)
counter2 = get(hObject, 'UserData') - 1;
set(hObject, 'UserData', counter2);
set(handles.Impt, 'String', sprintf('Number of Patients currently: %d\n', counter2));
guidata(hObject , handles);
What should i change to the minus code.
  댓글 수: 10
Walter Roberson
Walter Roberson 2018년 3월 13일
Impt_CreateFcn is missing.
For both patient_Callback and patients_Callback, you use
counter2 = get(hObject, 'UserData')
but notice that for patient_Callback, hObject is data attached to handles.patient, and for patients_Callback, hObject is data attached to handles.patients . You are not using the same data.
You should change patients_Callback to access handles.patient rather than hObject .
Kwan Zhao Jie
Kwan Zhao Jie 2018년 3월 13일
Thanks! It works now!

댓글을 달려면 로그인하십시오.

답변 (1개)

Santosh Prasad Choudhury
Santosh Prasad Choudhury 2018년 3월 12일
Please try to check the user data deafult value and how you validate them for value less than 0? please let me know

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by