Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Delete plot

Subject: Delete plot

From: Keith Azzopardi

Date: 14 Feb, 2013 16:54:06

Message: 1 of 8

I have a GUI application where I need to display several pcolor plots. I have one graph area and using a scroll bar to display the next plot. For each pcolor plot, I am also displaying a quiver plot which can be disabled via a radio button. However, the following error occurs:

Error using delete
Invalid or deleted object.

Snippet:
windDirStatus = get(hObject,'Value');
axes(handles.graph);

if (windDirStatus)
        windDirection = quiver (xaxis,yaxis,windUplot,windVplot);
        hold on;
else
       % set(windDirection,'Visible','off');
       delete(windDirection);
       
end


Can somebody help me with this issue please?

Subject: Delete plot

From: Steven_Lord

Date: 14 Feb, 2013 19:49:18

Message: 2 of 8



"Keith Azzopardi" <keithazzopardi@hotmail.com> wrote in message
news:kfj4re$7ve$1@newscl01ah.mathworks.com...
> I have a GUI application where I need to display several pcolor plots. I
> have one graph area and using a scroll bar to display the next plot. For
> each pcolor plot, I am also displaying a quiver plot which can be
> disabled via a radio button. However, the following error occurs:
>
> Error using delete
> Invalid or deleted object.
>
> Snippet:
> windDirStatus = get(hObject,'Value');
> axes(handles.graph);
>
> if (windDirStatus) windDirection = quiver
> (xaxis,yaxis,windUplot,windVplot);
> hold on;
> else
> % set(windDirection,'Visible','off');
> delete(windDirection);
> end
>
> Can somebody help me with this issue please?

There's no guarantee that windDirStatus has been true, and QUIVER been
called to create a new plot, between two calls to DELETE. You will probably
want to keep track of that and only DELETE if a new graphic to delete was
created.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Delete plot

From: dpb

Date: 14 Feb, 2013 19:51:23

Message: 3 of 8

On 2/14/2013 10:54 AM, Keith Azzopardi wrote:
> I have a GUI application where I need to display several pcolor plots. I
> have one graph area and using a scroll bar to display the next plot. For
> each pcolor plot, I am also displaying a quiver plot which can be
> disabled via a radio button. However, the following error occurs:
>
> Error using delete
> Invalid or deleted object.
>
> Snippet:
> windDirStatus = get(hObject,'Value');
> axes(handles.graph);
>
> if (windDirStatus) windDirection = quiver
> (xaxis,yaxis,windUplot,windVplot);
> hold on;
> else
> % set(windDirection,'Visible','off');
> delete(windDirection);
> end
>
> Can somebody help me with this issue please?

Well, not from the above alone...the error indicates that you've got a
sequencing problem, perhaps in that the handle you are trying to delete
has already been deleted--or, possibly the windDirStatus value isn't .T.
so that the if clause that creates the quiver isn't occurring.

You don't provide enough context to know what hObject is actually
pointing to nor anything at all about the overall sequence so other than
the obvious that the handle you're trying to delete isn't valid at the
time of the call, there's not much that can be said definitively as to why.

--

Subject: Delete plot

From: Yuri Geshelin

Date: 14 Feb, 2013 20:15:07

Message: 4 of 8

"Keith Azzopardi" <keithazzopardi@hotmail.com> wrote in message <kfj4re$7ve$1@newscl01ah.mathworks.com>...
> I have a GUI application where I need to display several pcolor plots. I have one graph area and using a scroll bar to display the next plot. For each pcolor plot, I am also displaying a quiver plot which can be disabled via a radio button. However, the following error occurs:
>
> Error using delete
> Invalid or deleted object.
>
> Snippet:
> windDirStatus = get(hObject,'Value');
> axes(handles.graph);
>
> if (windDirStatus)
> windDirection = quiver (xaxis,yaxis,windUplot,windVplot);
> hold on;
> else
> % set(windDirection,'Visible','off');
> delete(windDirection);
>
> end
>
>
> Can somebody help me with this issue please?

As dpb pointed out, you didn't provide enough information to help you, but try the following. Instead of deleting and re-creating the vector plot, toggle its 'visible' property between ON and OFF. In any case, this seems to be a better strategy, because it will work faster (I think).

Subject: Delete plot

From: Keith Azzopardi

Date: 15 Feb, 2013 09:21:11

Message: 5 of 8

Yuri, I tried setting the visibility to false, however the same error occurs.







"Yuri Geshelin" wrote in message <kfjgkb$ntc$1@newscl01ah.mathworks.com>...
> "Keith Azzopardi" <keithazzopardi@hotmail.com> wrote in message <kfj4re$7ve$1@newscl01ah.mathworks.com>...
> > I have a GUI application where I need to display several pcolor plots. I have one graph area and using a scroll bar to display the next plot. For each pcolor plot, I am also displaying a quiver plot which can be disabled via a radio button. However, the following error occurs:

further details
the snippet is in the radio button call back function, thus the hObject is a handle to the radio button.
Furthermore, windDirStatus is a local variable while windDirection is a global variable.

Full error is

Error using delete
Invalid or deleted object.

Error in menu>windDirectionButton_Callback (line 130)
      delete(windDirection);

Error in gui_mainfcn (line 96)
        feval(varargin{:});

Error in menu (line 18)
    gui_mainfcn(gui_State, varargin{:});

Error in
@(hObject,eventdata)menu('windDirectionButton_Callback',hObject,eventdata,guidata(hObject))

 
Error while evaluating uicontrol Callback



> >
> > Error using delete
> > Invalid or deleted object.
> >
> > Snippet:
> > windDirStatus = get(hObject,'Value');
> > axes(handles.graph);
> >
> > if (windDirStatus)
> > windDirection = quiver (xaxis,yaxis,windUplot,windVplot);
> > hold on;
> > else
> > % set(windDirection,'Visible','off');
> > delete(windDirection);
> >
> > end
> >
> >
> > Can somebody help me with this issue please?
>
> As dpb pointed out, you didn't provide enough information to help you, but try the following. Instead of deleting and re-creating the vector plot, toggle its 'visible' property between ON and OFF. In any case, this seems to be a better strategy, because it will work faster (I think).

Subject: Delete plot

From: Keith Azzopardi

Date: 15 Feb, 2013 11:59:18

Message: 6 of 8

Yuri, I tried setting the visibility to false, however the same error occurs.

further details
the snippet is in the radio button call back function, thus the hObject is a handle to the radio button.
Furthermore, windDirStatus is a local variable while windDirection is a global variable.

Full error is

Error using delete
Invalid or deleted object.

Error in menu>windDirectionButton_Callback (line 130)
      delete(windDirection);

Error in gui_mainfcn (line 96)
        feval(varargin{:});

Error in menu (line 18)
    gui_mainfcn(gui_State, varargin{:});

Error in
@(hObject,eventdata)menu('windDirectionButton_Callback',hObject,eventdata,guidata(hObject))

 
Error while evaluating uicontrol Callback


"Yuri Geshelin" wrote in message <kfjgkb$ntc$1@newscl01ah.mathworks.com>...
> "Keith Azzopardi" <keithazzopardi@hotmail.com> wrote in message <kfj4re$7ve$1@newscl01ah.mathworks.com>...
> > I have a GUI application where I need to display several pcolor plots. I have one graph area and using a scroll bar to display the next plot. For each pcolor plot, I am also displaying a quiver plot which can be disabled via a radio button. However, the following error occurs:
> >
> > Error using delete
> > Invalid or deleted object.
> >
> > Snippet:
> > windDirStatus = get(hObject,'Value');
> > axes(handles.graph);
> >
> > if (windDirStatus)
> > windDirection = quiver (xaxis,yaxis,windUplot,windVplot);
> > hold on;
> > else
> > % set(windDirection,'Visible','off');
> > delete(windDirection);
> >
> > end
> >
> >
> > Can somebody help me with this issue please?
>
> As dpb pointed out, you didn't provide enough information to help you, but try the following. Instead of deleting and re-creating the vector plot, toggle its 'visible' property between ON and OFF. In any case, this seems to be a better strategy, because it will work faster (I think).

Subject: Delete plot

From: Yuri Geshelin

Date: 15 Feb, 2013 15:22:06

Message: 7 of 8

"Keith Azzopardi" <keithazzopardi@hotmail.com> wrote in message <kfl7um$m0b$1@newscl01ah.mathworks.com>...
> Yuri, I tried setting the visibility to false, however the same error occurs.
>
> further details
> the snippet is in the radio button call back function, thus the hObject is a handle to the radio button.
> Furthermore, windDirStatus is a local variable while windDirection is a global variable.
>
> Full error is
>
> Error using delete
> Invalid or deleted object.
>
> Error in menu>windDirectionButton_Callback (line 130)
> delete(windDirection);
>
> Error in gui_mainfcn (line 96)
> feval(varargin{:});
>
> Error in menu (line 18)
> gui_mainfcn(gui_State, varargin{:});
>
> Error in
> @(hObject,eventdata)menu('windDirectionButton_Callback',hObject,eventdata,guidata(hObject))
>
>
> Error while evaluating uicontrol Callback
>
>
> "Yuri Geshelin" wrote in message <kfjgkb$ntc$1@newscl01ah.mathworks.com>...
> > "Keith Azzopardi" <keithazzopardi@hotmail.com> wrote in message <kfj4re$7ve$1@newscl01ah.mathworks.com>...
> > > I have a GUI application where I need to display several pcolor plots. I have one graph area and using a scroll bar to display the next plot. For each pcolor plot, I am also displaying a quiver plot which can be disabled via a radio button. However, the following error occurs:
> > >
> > > Error using delete
> > > Invalid or deleted object.
> > >
> > > Snippet:
> > > windDirStatus = get(hObject,'Value');
> > > axes(handles.graph);
> > >
> > > if (windDirStatus)
> > > windDirection = quiver (xaxis,yaxis,windUplot,windVplot);
> > > hold on;
> > > else
> > > % set(windDirection,'Visible','off');
> > > delete(windDirection);
> > >
> > > end
> > >
> > >
> > > Can somebody help me with this issue please?
> >
> > As dpb pointed out, you didn't provide enough information to help you, but try the following. Instead of deleting and re-creating the vector plot, toggle its 'visible' property between ON and OFF. In any case, this seems to be a better strategy, because it will work faster (I think).

Yes, I see, it is commented out in your first version. But obviously you still have the DELETE statement in your code. Why? It simply should not be there if you toggle the VISIBLE property between ON and OFF.

Subject: Delete plot

From: dpb

Date: 15 Feb, 2013 15:31:28

Message: 8 of 8

On 2/15/2013 5:59 AM, Keith Azzopardi wrote:

...[top posting repaired--don't: hard follow conversation makes]...

> "Yuri Geshelin" wrote in message <kfjgkb$ntc$1@newscl01ah.mathworks.com>...
>> "Keith Azzopardi" <keithazzopardi@hotmail.com> wrote in message
>> <kfj4re$7ve$1@newscl01ah.mathworks.com>...
>> > I have a GUI application where I need to display several pcolor
>> plots. I have one graph area and using a scroll bar to display the
>> next plot. For each pcolor plot, I am also displaying a quiver plot
>> which can be disabled via a radio button. However, the following error
>> occurs:
>> > > Error using delete
>> > Invalid or deleted object.
>> > > Snippet:
>> > windDirStatus = get(hObject,'Value');
>> > axes(handles.graph);
>> > > if (windDirStatus) > windDirection = quiver
>> (xaxis,yaxis,windUplot,windVplot);
>> > hold on;
>> > else
>> > % set(windDirection,'Visible','off');
>> > delete(windDirection);
>> > > end > > > Can somebody help me with this issue please?
>>
>> As dpb pointed out, you didn't provide enough information to help you,
>> but try the following. Instead of deleting and re-creating the vector
>> plot, toggle its 'visible' property between ON and OFF. In any case,
>> this seems to be a better strategy, because it will work faster (I
>> think).

> Yuri, I tried setting the visibility to false, however the same
> error occurs.

Of course--if the handle is invalid, it's invalid for whatever
reason/purpose you try to make of it...

 > further details
> the snippet is in the radio button call back function, thus the
> hObject is a handle to the radio button.

...

I don't write guis, but from the doc's for a radiobutton I find the
following--

> If the radio button is selected, its Value property is equal to its
> Max property. If the radio button is not selected, it is equal to its
> Min property.

I don't know what the Min/Max properties are, but I'm guessing your if()
test isn't being satisfied as S Lionel suggested.

The example code snippet in the doc uses a test written as

if (get(hObject,'Value') == get(hObject,'Max'))
% Radio button is selected, take appropriate action
else
% Radio button is not selected, take appropriate action
end

--

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us