how i use "edit text" as input and "push button" as output in gui

16 views (last 30 days)
i have program in matlab where in command window i give data as a input and after select method it give me output(sum,mult etc)
i want to do the same by gui. a 'edit text' where i can enter number as a input an push button which increment or decrement the input and a push button show the output in the same edit text box.

Answers (2)

Geoff Hayes
Geoff Hayes on 28 Jan 2015
Check http://www.mathworks.com/discovery/matlab-gui.html for some details (with videos) on how to build a GUI. In your case, it seems clear - use GUIDE to create a GUI with an edit text box and a push button. If the former is named edit1 and the latter is named pushbutton1 then all you need to do is define the callback for the push button. Something like
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% get the value from the text box and convert to a number
val = str2num(char(get(handles.edit1,'String')));
% do some work using val
It may be that you need two edit text boxes if you are adding, subtracting or multiplying two numbers. Start with something simple and see what happens!
  2 Comments
Daniel Liberman
Daniel Liberman on 14 Mar 2020
Hi,
What do I need to do if I want to get a numeric vector from the user in the edit text box?
Geoff Hayes
Geoff Hayes on 14 Mar 2020
Daniel - are the numbers in the text box separated by spaces or commas? If spaces, why can't str2num be used (which should create a numeric array)?

Sign in to comment.


Saleh Abumousa
Saleh Abumousa on 14 Dec 2020
in gui guide editor text use to

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!