GUI option to return no output

1 Ansicht (letzte 30 Tage)
CAM
CAM am 2 Okt. 2014
Kommentiert: CAM am 3 Okt. 2014
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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 2 Okt. 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..
  1 Kommentar
CAM
CAM am 3 Okt. 2014
Thank you. The straight-forward method seems to be the way to go. However I now have a follow-up question: how to I cover the user just clicking the window-close button ("x" in upper right corner)? What callback fires in that situation? Based on the suggested option, the window-close button acts like Accept. This leads me to think that the other option (saving the button press) may be better, provided I default strExitButton to "Cancel" during OpeningFcn().
BTW, when does OutputFcn() fire at startup? When I put a break-point in my code, it only breaks upon shutdown.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by