how i use "edit text" as input and "push button" as output in gui
10 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (2 件)
Geoff Hayes
2015 年 1 月 28 日
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 件のコメント
Daniel Liberman
2020 年 3 月 14 日
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
2020 年 3 月 14 日
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)?
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!