G'day everyone, this is my first post to this forum though it has already helped me many times in the past.
I am developing my first GUI using GUIDE, it essentially opens a set of 2D data maps and displays them whilst plotting some data taken from them. I have generated an impoint so that the user is able to select a location on the image for processing (it is actually taking the average of a group of pixels around that point). I have set up boundary limits to prevent the data point from being dragged too close to the edge (where the 'superpixel' would be out of range). The size of the group of pixels is defined as a s*s square. When 's' is changed by the user, a callback is run which may relocate the data point further from the edge if it is too close and also update the processing around that point. Generally, this is all running well.
I have an automatic callback triggered by the movement of the impoint using:
I have written a function 'get_pos()' which essentially updates the handles for the position of the impoint and updates a plot using the data from this point.
When I attempt to enter a new value for 's' through the user interface and the callback for this change is executed, the program essentially needs to update the position of the data point. So when the setPosition function (an matlab function for the impoint) is run, from within the callback function, the handles don't get updated prior to the updating of the position, this causes an error to be caught within my superpixel function - saying that the desired point is too close to the edge for that value of 's'.
For example, if I set s = 11 and then attempt to change it to s = 5, it calls the callback for the editable text box and 's' is initally changed to 5. I attempt to update the handles after 's' is updated using the following, but it does not seem to be updated prior to the api callback from being run:
I've also tried the following in order to update the handles, with no success (in this case):
handles = guidata(hObject);
I think what I need to know is why my handles are not updating prior to the api callback. I have been updating the handles fine is all other areas of the code. I thought maybe the api execution is called internally before the handles are updated perhaps, but I'm not sure how I can really debug this.
I've got a feeling this problem may be a little too in depth to explain on a forum, but you guys are pretty awesome at this stuff ;-)
I didn't fully appreciate and understand the usage of the guidata function and in order to update the function called within the api callback I needed to update the state of the internal 'handles' variable. I was close before, I needed to add the follow to the start of the get_pos function:
handles = guidata(hObject);
whereas prior to this I was running guidata(hObject, handles) above it in the function - effectively overwriting the handles variable before I used it.
"Michael " <firstname.lastname@example.org> wrote in message ...
> I have an automatic callback triggered by the movement of the impoint using:
> api.addNewPositionCallback(@(pos) get_pos(pos, hObject, handles));