NBUTTONDLG: A Generic Implementation of QUESTBOXDLG

Version 1.0.0.0 (5.03 KB) by sco1
Generates an n-button question dialog box
76 Downloads
Updated 12 Oct 2022

An expansion over QUESTBOXDLG, which allows up to 3 button selections, NBUTTONDLG(Question, ButtonLabels) creates a modal dialog box that sizes to accomodate a generic number of buttons. The number of buttons is determined by the number of elements in buttonlabels, a 1xn cell array of strings. The name of the button that is pressed is returned as a string in userchoice. NBUTTONDLG will theoretically support an infinite number of buttons. The default parameters are optimized for 4 buttons.
NBUTTONDLG returns the label of the selected button as a character array. If the dialog window is closed without a valid selection the return value is empty.
NBUTTONDLG uses UIWAIT to suspend execution until the user responds.
Example:
UserChoice = nbuttondlg('What is your favorite color?', ...
{'Red', 'Green', 'Blue', 'Yellow'} ...
);
if ~isempty(UserChoice)
fprintf('Your favorite color is %s!\n', UserChoice);
else
fprintf('You have no favorite color :(\n')
end

The Question and ButtonLabel inputs can be followed by parameter/value pairs to specify additional properties of the dialog box. For example, NBUTTONDLG(Question, ButtonLabels, 'DialogTitle', 'This is a Title!') will create a dialog box with the specified Question and ButtonLabels and replace the default figure title with 'This is a Title!'

Cite As

sco1 (2024). NBUTTONDLG: A Generic Implementation of QUESTBOXDLG (https://github.com/StackOverflowMATLABchat/nbuttondlg), GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Dialog Boxes in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes
1.0.0.0

Update version requirement from R2007a to R2009b due to use of tilde operator in function calls.

Fixed handle graphics compatibility issues requiring R2014b or later. Should now work with MATLAB 2007a and later.

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.