I'm making a GUI with Matlab's guide. I'm placing points with impoint, and I use addNewPositionCallback to be able to update my 'point list'. One of the arguments given to my update function that I give as a callback, is the 'handles' object. But Matlab passes this by value, so when the callback is called, I do have the handles object there but it's an outdated version. I would like to have something like a pointer to the handles object.
Or more general: I would like to access the 'handles' object somewhere in a function where I don't have it as a parameter.
Edit: So I have a callback function that look like this:
function updatePosition(pos, hObject, handles)
Which I add as a callback like this:
addNewPositionCallback(testh,@(pos) updatePosition(pos, hObject, handles));
And I have a pointlist in the handles, handles.pointlist. It should contain 5 points, but when I have an updatePosition call for the first point, the list contains just one point: the handles does not seem to be updated, it just has a copy from earlier on.
Like javascript, matlab script can create closures as function handles. That means it can 'capture' variables. You can create updatePosition in a context where you do have access to the handles object. You should do it like this:
H = handles.figure1; % get the figure handle
updatePosition = @(p) get(guihandles(H)... % the guihandles(H) contains the handles structure of the figure. Do whatever you need with it.
addNewPositionCallback(testh,updatePosition);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With