How to create a counter to add and minus?

1 回表示 (過去 30 日間)
Kwan Zhao Jie
Kwan Zhao Jie 2018 年 3 月 7 日
編集済み: Kwan Zhao Jie 2018 年 3 月 7 日
Im creating a simple counter which helps to add on one button and subtracts when pressing another button. I have done abit of research on this website previously and i found this code. but when i try and change the counter to minus. it doesnt work. Im using MATLAB R2013b GUIDE.
function nurse_Callback(hObject, eventdata, handles)
counter = get(hObject, 'UserData') + 1;
set(hObject, 'UserData', counter);
set(handles.Impt, 'String', sprintf('Number of Nurses currently: %d\n', counter));

採用された回答

Image Analyst
Image Analyst 2018 年 3 月 7 日
Maybe try calling guidata() at the end.
  1 件のコメント
Kwan Zhao Jie
Kwan Zhao Jie 2018 年 3 月 7 日
編集済み: Kwan Zhao Jie 2018 年 3 月 7 日
For minus should i. btw i got the set(handles.text8,'string','0') in the opening function alr.
counter = get(hObject, 'UserData') - 1;
set(hObject, 'UserData', counter);
set(handles.Impt, 'String', sprintf('Number of Nurses currently: %d\n', counter));
guidata()

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by