How to plot in an axes Object in a GUI?

Hi, I created a GUI with guide. There's plenty of text, scrollbars, buttons and buttongroups. It all works fine except the plot I have: whenever I try to plot some data into my axes object which I called 'guiGraph' it either opens a new figure and resets the main GUI, or an error is thrown to the console. I've tried all the tricks that are listed on the forums and really don't know what can be wrong with the code. This is what I've put in the callback function of one button:
x = 1:100;
y = sin(x*pi/180);
set(handles.figure1,'CurrentAxes',handles.guiGraph)
handles.guiGraph
h = get(gcf,'CurrentAxes')
plot(x, y);
h = get(gcf,'CurrentAxes')
On the console I always get the same values displayed for handles.guiGraph and the first h=get(...), after the plot command h=get(..) assumes another value. The execution of the plot command opens anew figure where the graph is plotted while my Gui becomes a gray canvas. Of course I tried even to change the plot command to this:
plot(h,x, y);
everything but the axes in my gui disappears and it throws following error messages:
Error using handle.handle/set
Invalid or deleted object.
Error in newplot (line 66)
set(fig,'nextplot','add');
Error in GK_Gui>buttonStart_Callback (line 134)
plot(h,x, y);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in GK_Gui (line 43)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)GK_Gui('buttonStart_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
What is wrong with the code?

Answers (0)

Categories

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

Asked:

on 11 Apr 2013

Community Treasure Hunt

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

Start Hunting!