How do I make a push button output a value of '1' to a text box, and then use that value and a double?
조회 수: 10 (최근 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.
댓글 수: 0
채택된 답변
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 Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!