Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create and show graphics more of one time over the same axes?

Status
Not open for further replies.

Guest


Hi anyone,

My application contains a graphic called ‘AxeSpot’. To show it I push a button. The button’s callback executes the following code:

% Get the main figure’s handle
hfmain=findobj('Tag','FigMain'); % Main Figure’s handle.

% Create the ‘AxeSpot’ axes (which is a main figure’s child) with certains properties.
h1 = axes('Parent',hfmain, ...
'Units','pixels', ...
'Position',[181 228 177 104], ...
'Tag','AxeSpot', ...
'Color',[1 1 1], ...
'Layer','top', ...
'Visible','on',...
'XColor',[1 1 1], ...
'YColor',[1 1 1]);

hspot=findobj('Tag','AxeSpot'); % This sentence asign a handle to ‘AxeSpot’ axes.
axes(hspot); % This sentence select ‘AxeSpot’ as current axes.
set(hspot,'NextPlot','add'); % This sentence add the nexplot to ‘AxeSpot’ axes.
spot(v_out); % This is the function that show the plot over the %‘AxeSpot’ axes.

But there is a trouble: The first time I push the button, the graphics is created and the plot is added to ‘AxeSpot’ axes. However, the following times I push the button, the program does not work and an error arises. The error says: hfmain invalid handle in line …. The program line of which I talk is that where I create the axes again:

h1 = axes('Parent',hfmain, ...
'Units','pixels', ...
'Position',[181 228 177 104], ...
.
.
.
.
Which is the problem reason? Why does it not work? Do you know how to solve it?

Thanks in advance,

Cris


 
Replies continue below

Recommended for you

Hi,
The trouble is hidden somewhere. But if you use findobj again just before creating the axes you will solve it anyway. In general it is better to hide objects (setting the 'visible' property to 'off') then recreate it again and again.

Joe
BSTEX - Equation viewer for Matlab
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor