Unknown axes in GUI
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I compiled a simple GUI program and when running it a unknown axis appears and can be visible under the START button. When running the GUI, it opens one figure which is updated via defined fig handle on every step.
![GUI_Matlab_dec19.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199607/image.png)
I have gone thourght the code line by line and another axis is not defined. So any idea wherefrom this axis? How shall I remove it?
1 comentario
Walter Roberson
el 22 de Dic. de 2018
Difficult for us to say without access to the code.
Does the same problem occur when you are running in MATLAB interactively instead of compiling ?
Respuesta aceptada
vik
el 22 de Dic. de 2018
When calling plot or axes you can optionally specify a "parent" or "container", where the axes or plot object gets created in. The container is the handle object to the object where the new object will be created in. If you don't specify the container, it will be created in the "current figure" or "current axes". This can be literally anything you created or selected with your mouse before.
If you call plot and no current axes or figure exists, it will create the missing figure window, create an axes object inside it and then creates the plot into the axes.
See this example which creates some figures and uses a button in one window to plot something in another window (also attached):
function example_436887
% Create thee new figure windows
h_fig1 = figure;
h_fig2 = figure;
h_fig3 = figure;
% Create axes manually
h_ax2 = axes(h_fig2); % axes(container,...)
h_ax3 = axes(h_fig3);
% Plot something in h_ax2 which is in h_fig2
plot(h_ax2,1:10,rand(1,10))
% Modify Size of h_fig1 and disable menu bar and toolbar
h_fig1.Position(3) = 350;
h_fig1.Position(4) = 100;
set(h_fig1,'MenuBar','none',...
'ToolBar','none');
% Create a Button in h_fig1
button_plot = uicontrol(h_fig1, ... % use h_fig1 as parent container
'Style','pushbutton',...
'String','Call Plot in Figure specified as h_fig3', ...
'Position',[20,20,300,25],...
'Callback',@button_plot_Callback);
function button_plot_Callback(source,eventdata)
% Plot something in h_ax3:
plot(h_ax3,1:10,rand(1,10)); % plot into parent container h_ax3
end % function button_plot_Callback
end % function example_436887
When pushing the button to plot inside h_fig1, the target container needs to be specified. If you change the Callback-Function from this:
function button_plot_Callback(source,eventdata)
% Plot something in h_ax3:
plot(h_ax3,1:10,rand(1,10)); % plot into parent container h_ax3
end % function button_plot_Callback
to this:
function button_plot_Callback(source,eventdata)
% Plot something in h_ax3:
plot(1:10,rand(1,10)); % plot into current axes/figure
end % function button_plot_Callback
The error you described occurs, as the plot command creates an axes in the current figure (which is the figure with the button) because there is no axes to plot into.
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Object Programming en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!