MATLAB Answers

GUI function from Edit

3 views (last 30 days)
Hello matlab people community
I am so new to use matlab. I try to take some function respect to x, from edit1 which is name of the component, then I push a button , function of plot will see on the axes? I need a code how to call the function from the edit?
I write the codes here
function pushbutton1_Callback(hObject, eventdata, handles)
axes(handles.axes1);
x=0:0.1:10;
handles.a = get(handles.edit1,'String');
plot(x,a);
Thanks!!!
  3 Comments
engineerOfPhysics
engineerOfPhysics on 13 Mar 2013
It means for example I write sin(x) then I push the button on the axes the graph of sinx will be seen. In the same GUI ?

Sign in to comment.

Accepted Answer

engineerOfPhysics
engineerOfPhysics on 13 Mar 2013
How to convert string to function in GUİ ? come on guys I need your help !!
  6 Comments
Image Analyst
Image Analyst on 19 Mar 2013
Just FYI: generally you don't post an "Answer" to your own question when it's really a comment, and you don't accept _you_r Answer unless you were really the person who came up with the solution (instead of Allessandro).

Sign in to comment.

More Answers (2)

Alessandro
Alessandro on 13 Mar 2013
Edited: Alessandro on 13 Mar 2013
you got there a string maybe you should first convert it to an array ! Try this simple solution:
handles.a = get(handles.edit1,'String');
tmpa = str2num(handles.a)
plot(x,tmpa);
  2 Comments
engineerOfPhysics
engineerOfPhysics on 13 Mar 2013
And I try your solution does not work

Sign in to comment.


engineerOfPhysics
engineerOfPhysics on 13 Mar 2013
Edited: engineerOfPhysics on 13 Mar 2013
I am working on a GUI. I want to draw a function. I want to take the function which can be sin(x) or x^4 or 3*x+5 from the user, then when I push the button the graph of the function will be seen on the asex1. User writes function on the edit1 component.
Is there any way to do that? I need a some code which make convert the string to the function so GUI can plot. ?
Please help. I could not solve ..
Thanks...

Community Treasure Hunt

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

Start Hunting!