GUI option to return no output
1 view (last 30 days)
Show older comments
I am programming a GUI that waits (uiwait) for the user to select some points on an axes object. I have one pushbutton ("Accept") that closes the figure and returns the points' coordinates.
However I have another button ("Cancel") that I just want to close the figure, but return nothing.
I have viewed and implemented the setup in Doug Hull's video (using uiresume, delete(hObject), etc). But whether I close the figure with Accept, Cancel or the window-close button, the OutputFcn is always called.
I have 2 thoughts on overcoming this. Since I am using appdata to store the points, I thought that I could:
- Set the return variable to empty within appdata when the Cancel button is clicked, or
- Store another variable in appdata, called strExitButton, where I set it to name of the button clicked. Then that value is called up in OutputFcn to determine whether to return the coordinates or an empty matrix.
Is there a better way to do this? If not, which option above is the better choice?
Many thanks in advance.
0 Comments
Accepted Answer
Image Analyst
on 2 Oct 2014
You can have some variable that you want to return, maybe call it output. In Cancel, just use setappdata() to set output to null. In "Accept", use setappdata() to set output to whatever you want, like some double array ("the coordinates", or a string, or structure or whatever you want to return. I would not set it equal to the name of the button - what's the point, it's just more work to do because then you'd have to check that and just set output accordingly anyway? Just set the output directly in the button callback itself with setappdata() or global() and recall it in the outputFcn with getappdata() or global. By the way, the OutputFcn() gets called both upon startup and upon shutdown..
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!