"Alex " <email@example.com> wrote in message news:firstname.lastname@example.org... > 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.