MATLAB Answers

How to input points and numbers into GUI

조회 수: 85(최근 30일)
Kneel Armstrong
Kneel Armstrong 23 Jul 2014
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.

  댓글 수: 0

로그인 to comment.

답변(3개)

Joseph Cheng
Joseph Cheng 23 Jul 2014
편집: Joseph Cheng 23 Jul 2014
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.

  댓글 수: 0

로그인 to comment.


Michael Haderlein
Michael Haderlein 23 Jul 2014
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

표시 이전 댓글 수: 6
Michael Haderlein
Michael Haderlein 28 Jul 2014
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 28 Jul 2014
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 29 Jul 2014
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.

로그인 to comment.


Arun Bisoyi
Arun Bisoyi 23 Jul 2014
편집: Arun Bisoyi 23 Jul 2014
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..

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그


Translated by