From: Megan on
Is there any way to "deselect" the axis in a GUI so that calling plot from the command line will plot to a new figure and not the axis the GUI figure?

A very simplified version of the GUI is below, which demonstrates the problem. The original allows the user to input the x and y values, and determines the polynomial coefficients.

When the GUI is run, without yet plotting anything on the axis (using the pushbutton), typing plot(0.1:0.1:10) in the command line (or selecting an existing variable in the workspace and clicking the "plot" icon) will base workspace data in a new figure window as expected.

Once there is data plotted in the GUI, the same action will cause the plot to appear in the GUI, overwriting the existing data. If I select/create another figure and have it as the active figure, then the plot is created there and not in the GUI, but I don't generally remember (or want) to do this.

The GUI figure's NextPlot property is set to new, which seems to work as long as there is nothing plotted. I've tried setting the axes HandleVisibility property to both callback, and off, and neither seems to work. Is there some equivalent of gca I can add to the code that will deselect the axis/figure? Changing something in the preferences would also be acceptable to stop the default command line plot behaviour from grabbing the current figure.

I am using R2009b on Windows XP.

function [] = TestGUI()
%Create figure
S.fh = figure('Units','Pixels','Position',[400 300 390 430],'Menubar','figure','NextPlot','new',...
'Toolbar','figure','Numbertitle','off','Name','TestGUI','Resize','off');
S.ax = axes('Units','Pixels','Position',[60 120 306 269],'XLim',[0 1],'YLim',[0 1],'HandleVisibility','off');
S.pb = uicontrol(S.fh,'Style','pushbutton','Units','Pixels','Position',[20 20 350 50],'String','Plot Test Data','Callback',{@pb_call});

function [] = pb_call(varargin)
%Create sample data
x = [541,520,498,480,457,421,404,385,351,320];
y = [19.4,15.4,11.3,7.6,3.1,-2.4,-5.3,-8.7,-13.7,-17.9];
p = [0.00015318,0.037693,-45.713];
f1 = polyval(p,x);
%Plot
plot(S.ax,x,y,'xb',x,f1,'-r');
title(S.ax,'Original Data Points with Conversion');
xlabel(S.ax,'Raw Counts');
ylabel(S.ax,'EU Input');
legend(S.ax,'Data Points','Conversion','Location','NorthWest');
end %pb_call
end %TestGUI
From: Walter Roberson on
Megan wrote:
> Is there any way to "deselect" the axis in a GUI so that calling plot
> from the command line will plot to a new figure and not the axis the GUI
> figure?

I believe you can do this only by making a different axis the current axis.
You can delete that second axis afterwards, which would cause Matlab to
understand that there was no current axis. The following code should do:

delete(axes('Parent', gcf))


axes() sets the CurrentAxes property of the figure, and when there is no
current axes the CurrentAxes property is [], but set(gcf, 'CurrentAxes', [])
leaves the current axes unchanged (without any warning or error.)
From: Matt Fig on
In your initialization line, set the figures handlevisibility to 'callback'. Then on your AXES call, set the 'parent' property to S.fh.
From: Megan on
That fixed it. Thanks! I knew it was probably something little I was missing, but couldn't find it.