How to input points and numbers into GUI

I am trying to write my first GUI, so please be patient!!! I need to know how to create a box or field or something that I can type numbers into that will then be used when the GUI runs.

回答 (3 件)

Joseph Cheng
Joseph Cheng 2014 年 7 月 23 日
編集済み: Joseph Cheng 2014 年 7 月 23 日

0 投票

Check out the tutorial for GUIDE http://www.mathworks.com/discovery/matlab-gui.html There are several demos/simple templates examples that you can see what to do. for a field to type in you can use/draw an edit box using GUIDE.
Michael Haderlein
Michael Haderlein 2014 年 7 月 23 日

0 投票

A "please be patient" with three exclamation marks is somehow funny... You should have capitalized that sentence ;-)
One possibility is to use guide and create for instance a push button and an edit box. When you then write something like
msgbox(get(handles.edit1,'string'))
into the push button callback, you are close to what you need.
Alternatively, you can also create your GUI without guide by using uicontrol (remember to use the handles). Bit more work, but the code might be clearer, so that's my preferred way. It's up to you.
Best regards,
Michael

9 件のコメント

Kneel Armstrong
Kneel Armstrong 2014 年 7 月 23 日
I am a bit confused (now is Really the time for the capitalization). Let me give some background. I wrote a code that would graph a field, plot a point inside the field, and calculate the distances from the point to points along the perimeter of the field. Those points are determined by the intersection of the perimeter line segments with rays radiating from the point in question. (I will attach the code. Probably the best way to understand what I'm saying is to run it yourself.) The code has three inputs: subPT (the point contained within the field), vertPT(the points that make up the vertices of the field), and deg_Increment( which sets rays to radiate from subPT every x degrees). I now want to attach or somehow run this code from within a GUI. I have attached a possible configuration for this GUI. NOW (provided you haven't fallen asleep reading this), I would like to have subPT,vertPT, and deg_Increment entered within the GUI. I am not even sure how to run the code within the GUI, so any insight will be appreciated. I HAVE watched and read tutorials and instructions for writing GUIs, but I will learn better trying to write this myself and get first-hand experience rather than watch someone else do it. (By writing myself I don't mean that I don't want help--I DO--only that watching someone else write a program does not help me too much--I learn by doing.) Sorry for this long explanation. I am just learning MATLAB and need all the help I can get before it begins programming me rather than the other way round. SYNOPSIS: I want to run a function using GUI. The function has three inputs that I want to enter within the edit text boxes. I also want to give the choice to graph the field and intercepts and to export the distance file to Excel. The graph, of course, should appear in the axes box. I have attached my original function and a sample screen of what I envision the GUI looking like. The buttons are push buttons and the white boxes (excluding the axes box) are edit text boxes. Thanks for any help.
Kneel Armstrong
Kneel Armstrong 2014 年 7 月 23 日
Oh, how do you make your answers in this not be bunched together? The window I type in shows what I want but when I submit it, it doesn't have separate paragraphs, etc.
Michael Haderlein
Michael Haderlein 2014 年 7 月 24 日
Ok, let me get a bit more into details. I assume you want to do it with GUIDE. Insert a push button, an edit box and axes. Right click on the push -> View Callbacks -> Callback. The editor will open (after saving the fig and the m) and you see the following lines:
% --- 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)
You add the following lines:
x=linspace(0,2*pi);
plot(handles.axes1,x,sin(x*str2double(get(handles.edit1,'string'))))
As long as the text in the edit is only numbers, you will see a sin curve in the axes with the frequency depending on the value of the edit.
Instead of this sin curve, you can of course do any other kind of calculation and plotting.
Hope it's clearer now.
Best regards,
Michael
PS: For some reason, you need to do a double line break to get a new line here in the forum.
Kneel Armstrong
Kneel Armstrong 2014 年 7 月 24 日
編集済み: Kneel Armstrong 2014 年 7 月 24 日
I'll check what you sent. Yes, I am doing it with guide--it just seemed a bit easier for a beginner like me.
By the way, what IS a "double line break"? Do I press Enter twice or something?
Kneel Armstrong
Kneel Armstrong 2014 年 7 月 24 日
編集済み: Kneel Armstrong 2014 年 7 月 24 日
Just answered my last question. Thanks. Will post how GUI works.
Kneel Armstrong
Kneel Armstrong 2014 年 7 月 25 日
Ok, it doesn't seem to work. I do have three inputs, so one single pushbutton may be the problem--not sure.
Michael Haderlein
Michael Haderlein 2014 年 7 月 28 日
It doesn't matter how many inputs you have, here one example with three of them:
% --- 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)
x=linspace(0,2*pi);
a=str2double(get(handles.edit1,'string'));
b=str2double(get(handles.edit2,'string'));
c=str2double(get(handles.edit3,'string'));
plot(handles.axes1,x,a+b*sin(c*x))
Kneel Armstrong
Kneel Armstrong 2014 年 7 月 28 日
Still not working. I have attached a sample of what I want it to look like. Still can't get the edit boxes to input into GUI.
Michael Haderlein
Michael Haderlein 2014 年 7 月 29 日
I can't find your attachment, but if you
1. open guide,
2. create axes, a pushbutton and three edits,
3. right-click the pushbutton to open its callback,
4. modify the callback to the code above,
5. run the code
6. write some numbers into the edit boxes
7. push the pushbutton
you will get some sin curve based on the numbers in the edit boxes. Of course, do not rename any control.

サインインしてコメントする。

Arun Bisoyi
Arun Bisoyi 2014 年 7 月 23 日
編集済み: Arun Bisoyi 2014 年 7 月 23 日

0 投票

Hii Kneel,
what you have to do is :-
1. First open you GUIDE, then grab two object as :- 1)Edit 2)Push button
2. Double click on the Edit, then property inspector window opens, you have to change its name "Edit " to "Hit me"
3. Just do the same with Push button .
4. after that right click on any of the object and choose M-file from the option panel.
5. in the .m file go to pushbutton_callback function.in side the function body the code as i wrote below:-
6. write the code ;-
a=get(handles.edit1,'String')
b=strcat('you have entered=',a);
msgbox(b,'Conformation','warn');
save it by some file name.
7. Then just run it by pressing f5 or fn+f5 // run icon over the upper panel
waiting for your ack..

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

質問済み:

2014 年 7 月 23 日

コメント済み:

2014 年 7 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by