How do you pull data from a text box, and set it to plot?

Hello all, I have created a GUI that can do simple math by adding subtraction etc... and puts the results into a text box. What I want to do is take that single digit and plot it on a plane, I already know how to plot a graph if you hard type it in, but I want it to change with the calculated value. So I know it will be something like..
plot( function EXAMPLE, but I don't know how it goes after this.
I already have the push button to plot and the graph to have it plot on, I just need the correct coding to pull TEXT BOX A and graph that value!
Hope this makes sense

 Accepted Answer

Grant - presumably you are plotting the result of the calculation on an axes that is a part of your GUI. So in the callback to your push button, just do something like the following
function pushbutton1_Callback(hObject, eventdata, handles)
% get the data from text box A
data = str2num(char(get(handles.text1,'String')));
% do something with the data
% now plot it on the axes/graph
plot(handles.axes1,...);
The above assumes that you are using GUIDE to develop your GUI. The tag for your text box A is text1 and the tag for the axes is axes1.

5 Comments

Thanks Geoff I'll try this out later today!
Hey Geoff Just had a chance to look at this and plug it in and im assuming im missing something, although this is giving me a different error than I did before so I think it is very close to working!
My answer box that spits out the answer is tagged ANSWER and then I want it to on a push button display that point on the axis as (#,0) the zero because a single digit cannot be both points .... Here is the code
if true
% --- Executes on button press in Plot. function Plot_Callback(hObject, eventdata, handles) data = str2num(char(get(handles.ANSWER,'String'))); plot(handles.axes1); % hObject handle to Plot (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) end
So your plot command has to be something like
plot(handles.axes,data,0);
Are you expecting this to wipe out what was currently on the axes, or add to it, or..? Does the axes show just one point at any one time?
First thank you for your help, I am obviously not very proficient at this yet.
I wouldn't need it to clear out previous points that I have plotted but it would only plot one point at a time. If it is an extra step to keep previously plotted points, or if it an extra step to clear out previous plotted points, it doesn't have to happen. Whatever is simple.
Again thank you for your help, our professor has simply given us the users manual for MatLab with ZERO previous programming or code writing experience!
Grant
I suspect that the way it is working now is that the previous points are being cleared out. If you want to keep them, then in the OpeningFcn of your GUI, you could do something like
hold(handles.axes,'on');
which will retain previous calls to plot for the specified axes (i.e. previous plots won't be deleted).

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Asked:

on 14 Oct 2014

Commented:

on 16 Oct 2014

Community Treasure Hunt

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

Start Hunting!