GUI option to return no output
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2014-10-2
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..
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!