Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Problem with handles and continually updating plot in GUIDE
Replies: 5   Last Post: Aug 13, 2014 9:46 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 1,115
Registered: 9/26/13
Re: Problem with handles and continually updating plot in GUIDE
Posted: Aug 12, 2014 2:12 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


"Alex " <alex_pitterss@hotmail.co.uk> wrote in message
news:lsd9qe$959$1@newscl01ah.mathworks.com...
> I am having trouble with my continuously updating plot (using the handles
> structure).
>
> The key pieces are as follows:
>
> handles.sliderListener =
> addlistener(handles.slider1,'ContinuousValueChange', ...
> @(hObject, event)
> slider1ContValCallback(...
> hObject, eventdata, handles));


The third input to slider1ContValCallback will be a copy of the handles
structure AS IT EXISTS WHEN THIS LINE EXECUTES. Changes to the handles
structure after this line executes WILL NOT be reflected in that input
argument. This is NOT a bug.

> handles.x=rectangle('Position',[0,0,50,90],'facecolor','r');
>
>
> ^this is in the opening function, acting to start the listener for the
> slider, and draw a rectangle of the above dimensions.
>
> function slider1ContValCallback(hObject, eventdata, handles)
>
> get(handles.slider1, 'value')
>
> ^this is the function I have added to the GUIDE code to 'get' the slider's
> values.
>
> in the second function (slider1ContValCallback), I would also like to
> include a code to delete the rectangle inside this function. However, I am
> having trouble using the handles structure to do this.
> When I use the command:
>
> delete(handles.x)
>
> I get the following error:
>
> Reference to non-existent field 'x'.


That's correct. You added that field to the handles structure AFTER the copy
was made and stored in the anonymous function.

If you want slider1ContValCallback to be able to access all fields in the
handles structure, even those added or modified after the callback was set,
don't pass handles into the callback. Pass the handle to the object in and
use GUIHANDLES and/or GUIDATA to retrieve the handles structure inside the
callback instead.

*snip*

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




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.