Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

12 Commits

Repository files navigation

MATLAB FEXMinimum Version

nbuttondlg

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, provided as an array of string-likes understood by string. The name of the button that is pressed is returned as a string. If the dialog window is closed without a valid selection the return value is empty.

NBUTTONDLG should theoretically support an infinite number of buttons. The default parameters are optimized for 4 buttons.

NBUTTONDLG uses UIWAIT to suspend execution until the user responds.

Installation

No installation necessary. Clone the repository or download the files and execute directly in MATLAB.

Usage

Example:

user_choice = nbuttondlg('What is your favorite color?', ...
{'Red', 'Green', 'Blue', 'Yellow'} ...
);
if ~isempty(user_choice)
fprintf('Your favorite color is %s!\n', user_choice);
else
fprintf('You have no favorite color :(\n')
end

nbuttondlg

Parameter/Value Pairs

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!'

Property NameData TypeDescriptionDefault
BorderSizeIntegerSpacing, in pixels, between dialog box edges and button edges20
ButtonWidthIntegerWidth, in pixels, of all buttons80
ButtonHeightIntegerHeight, in pixels, of all buttons40
ButtonSpacingIntegerSpacing, in pixels, between all buttons20
PromptTextHeightIntegerHeight, in pixels, of the question text box20
DialogTitleString-likeDialog box figure title'Please Select an Option'
DefaultButtonInteger or String-likeDefault highlighted button.11
CancelButtonBooleanInclude a cancel button.2false
  1. An attempt will be made to match a string-like input to a value in ButtonLabels. If no match is found, or the integer value is greater than the number of buttons, the default value will be used.
  2. If true, a 'Cancel' button label is added to ButtonLabels. If Cancel is selected, NBUTTONDLG behaves as if it were closed without selection.

About

A Generic Implementation of QUESTDLG

Resources

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages