Unknown axes in GUI

조회 수: 4 (최근 30일)
rokP
rokP 2018년 12월 22일
댓글: rokP 2018년 12월 22일
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
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
Walter Roberson
Walter Roberson 2018년 12월 22일
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 ?

댓글을 달려면 로그인하십시오.

채택된 답변

vik
vik 2018년 12월 22일
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.
  댓글 수: 1
rokP
rokP 2018년 12월 22일
Thanks, your explanation helped, I have fixed the problem. The point is to activate the right fig/axis before plotting on it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by