필터 지우기
필터 지우기

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 CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by