フィルターのクリア

How do I make a push button output a value of '1' to a text box, and then use that value and a double?

20 ビュー (過去 30 日間)
I have a GUI that is supposed to act like a number pad, but I cannot get the buttons to actually output just a simple value. I am only attempting to get one button to work right now and will just mirror the results for the other buttons. I need help letting the button pass the value of '1' to display in a edit text box. This is for a touchscreen GUI so I need the number pad to be used to input values rather than a keyboard, please help.

採用された回答

Geoff Hayes
Geoff Hayes 2017 年 10 月 20 日
Bryce - how are you creating your GUI? With App Designer, GUIDE, or programmatically? In probably all three cases, your push button will have a callback and it is within that function that you will update the text box with the appropriate value.
If using GUIDE, you could do something like
% pushbutton1 is for the 1 key
function pushbutton1_Callback(hObject, eventdata, handles)
% get the current number from the text field
currentNumber = get(handles.text1, 'String');
% create the new number
newNumber = [currentNumber '1'];
% update the text
set(handles.text1, 'String', newNumber);
The callback uses the handle of the text field (from the handles structure as handles.text1) and gets the current string value. A '1' is then appended to this string and we then save it to the text field.
Your going to have a lot of duplicated code since there will be ten keys, so you may want to create a helper function that does much of the above.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by