Next: Progress Bar, Up: GUI Development [Contents][Index]

### 35.1 I/O Dialogs

Simple dialog menus are available for choosing directories or files. They return a string variable which can then be used with any command requiring a filename.

: dirname = uigetdir ()
: dirname = uigetdir (init_path)
: dirname = uigetdir (init_path, dialog_name)

  Open a GUI dialog for selecting a directory.

  If init_path is not given the current working directory is used.

  dialog_name may be used to customize the dialog title.

  See also: uigetfile, uiputfile.

: [fname, fpath, fltidx] = uigetfile ()
: […] = uigetfile (flt)
: […] = uigetfile (flt, dialog_name)
: […] = uigetfile (flt, dialog_name, default_file)
: […] = uigetfile (…, "Position", [px py])
: […] = uigetfile (…, "MultiSelect", mode)

  Open a GUI dialog for selecting a file and return the filename fname, the path to this file fpath, and the filter index fltidx.

  flt contains a (list of) file filter string(s) in one of the following formats:

  `"/path/to/filename.ext"`

    If a filename is given then the file extension is extracted and used as filter. In addition, the path is selected as current path and the filename is selected as default file. Example: `uigetfile ("myfun.m")`

  A single file extension `"*.ext"`

    Example: `uigetfile ("*.ext")`

  A 2-column cell array

    containing a file extension in the first column and a brief description in the second column. Example: `uigetfile ({"*.ext", "My Description";"*.xyz", "XYZ-Format"})`

    The filter string can also contain a semicolon separated list of filter extensions. Example: `uigetfile ({"*.gif;*.png;*.jpg", "Supported Picture Formats"})`

  A directory name or path name

    If the folder name of path name contains a trailing file separator, the contents of that folder will be displayed. If no trailing file separator is present the parent directory is listed. The substring to the right of the rightmost file separator (if any) will be interpreted as a file or directory name and if that file or directory exists it will be highlighted. If the path name or directory name is wholly or partly nonexistent, the current working directory will be displayed. No filter will be active.

  dialog_name can be used to customize the dialog title.

  If default_file is given then it will be selected in the GUI dialog. If, in addition, a path is given it is also used as current path.

  The screen position of the GUI dialog can be set using the `"Position"` key and a 2-element vector containing the pixel coordinates. Two or more files can be selected when setting the `"MultiSelect"` key to `"on"`. In that case fname is a cell array containing the files.

  See also: uiputfile, uigetdir.

: [fname, fpath, fltidx] = uiputfile ()
: [fname, fpath, fltidx] = uiputfile (flt)
: [fname, fpath, fltidx] = uiputfile (flt, dialog_name)
: [fname, fpath, fltidx] = uiputfile (flt, dialog_name, default_file)

  Open a GUI dialog for selecting a file.

  flt contains a (list of) file filter string(s) in one of the following formats:

  `"/path/to/filename.ext"`

    If a filename is given the file extension is extracted and used as filter. In addition the path is selected as current path and the filename is selected as default file. Example: `uiputfile ("myfun.m")`

  `"*.ext"`

    A single file extension. Example: `uiputfile ("*.ext")`

  `{"*.ext", "My Description"}`

    A 2-column cell array containing the file extension in the 1st column and a brief description in the 2nd column. Example: `uiputfile ({"*.ext","My Description";"*.xyz", "XYZ-Format"})`

  The filter string can also contain a semicolon separated list of filter extensions. Example: `uiputfile ({"*.gif;*.png;*.jpg", "Supported Picture Formats"})`

  dialog_name can be used to customize the dialog title. If default_file is given it is preselected in the GUI dialog. If, in addition, a path is given it is also used as current path.

  See also: uigetfile, uigetdir.

Additionally, there are dialog boxes for printing further help, warnings or errors and to get textual input from the user.

: h = errordlg ()
: h = errordlg (msg)
: h = errordlg (msg, title)
: h = errordlg (msg, title, createmode)

  Display an error dialog box with error message msg and caption title.

  The default error message is `"This is the default error string."` and the default caption is `"Error Dialog"`.

  The error message may have multiple lines separated by newline characters ("\n"), or it may be a cellstr array with one element for each line.

  The return value h is always 1.

  Compatibility Note: The optional argument createmode is accepted for MATLAB compatibility, but is not implemented. See `msgbox` for details.

  Examples:

      errordlg ("Some fancy error occurred.");
      errordlg ("Some fancy error\nwith two lines.");
      errordlg ({"Some fancy error", "with two lines."});
      errordlg ("Some fancy error occurred.", "Fancy caption");

  See also: helpdlg, inputdlg, listdlg, msgbox, questdlg, warndlg.

: h = helpdlg ()
: h = helpdlg (msg)
: h = helpdlg (msg, title)

  Display a help dialog box with help message msg and caption title.

  The default help message is `"This is the default help string."` and the default caption is `"Help Dialog"`.

  The help message may have multiple lines separated by newline characters ("\n"), or it may be a cellstr array with one element for each line.

  The return value h is always 1.

  Examples:

      helpdlg ("Some helpful text for the user.");
      helpdlg ("Some helpful text\nwith two lines.");
      helpdlg ({"Some helpful text", "with two lines."});
      helpdlg ("Some helpful text for the user.", "Fancy caption");

  See also: errordlg, inputdlg, listdlg, msgbox, questdlg, warndlg.

: cstr = inputdlg (prompt)
: cstr = inputdlg (prompt, title)
: cstr = inputdlg (prompt, title, rowscols)
: cstr = inputdlg (prompt, title, rowscols, defaults)
: cstr = inputdlg (prompt, title, rowscols, defaults, options)

  Return user input from a multi-textfield dialog box in a cell array of strings, or an empty cell array if the dialog is closed by the Cancel button.

  Inputs:

  prompt

    A cell array with strings labeling each text field. This input is required.

  title

    String to use for the caption of the dialog. The default is `"Input Dialog"`.

  rowscols

    Specifies the size of the text fields and can take three forms:

    1. a scalar value which defines the number of rows used for each text field.
    2. a vector which defines the individual number of rows used for each text field.
    3. a matrix which defines the individual number of rows and columns used for each text field. In the matrix each row describes a single text field. The first column specifies the number of input rows to use and the second column specifies the text field width.
  defaults

    A list of default values to place in each text fields. It must be a cell array of strings with the same size as prompt.

  options

    Not supported, only for MATLAB compatibility.

  Example:

      prompt = {"Width", "Height", "Depth"};
      defaults = {"1.10", "2.20", "3.30"};
      rowscols = [1,10; 2,20; 3,30];
      dims = inputdlg (prompt, "Enter Box Dimensions", rowscols, defaults);

  See also: errordlg, helpdlg, listdlg, msgbox, questdlg, warndlg.

: [sel, ok] = listdlg (key, value, …)

  Return user inputs from a list dialog box in a vector of selection indices (sel) and a flag indicating how the user closed the dialog box (ok).

  The indices in sel are 1-based.

  The value of ok is 1 if the user closed the box with the OK button, otherwise it is 0 and sel is empty.

  Input arguments are specified in form of key, value pairs. The `"ListString"` argument pair must be specified.

  Valid key and value pairs are:

  `"ListString"`

    a cell array of strings with the contents of the list.

  `"SelectionMode"`

    can be either `"Single"` or `"Multiple"` (default).

  `"ListSize"`

    a vector with two elements width and height defining the size of the list field in pixels. Default is [160 300].

  `"InitialValue"`

    a vector containing 1-based indices of preselected elements. Default is 1 (first item).

  `"Name"`

    a string to be used as the dialog caption. Default is "".

  `"PromptString"`

    a cell array of strings to be displayed above the list field. Default is {}.

  `"OKString"`

    a string used to label the OK button. Default is `"OK"`.

  `"CancelString"`

    a string used to label the Cancel button. Default is `"Cancel"`.

  Example:

      my_options = {"An item", "another", "yet another"};
      [sel, ok] = listdlg ("ListString", my_options,
                           "SelectionMode", "Multiple");
      if (ok == 1)
        disp ("You selected:");
        for i = 1:numel (sel)
          disp (sprintf ("\t%s", my_options{sel(i)}));
        endfor
      else
        disp ("You cancelled.");
      endif

  See also: menu, errordlg, helpdlg, inputdlg, msgbox, questdlg, warndlg.

: h = msgbox (msg)
: h = msgbox (msg, title)
: h = msgbox (msg, title, icon)
: h = msgbox (…, createmode)

  Display msg using a message dialog box.

  The message may have multiple lines separated by newline characters ("\n"), or it may be a cellstr array with one element for each line.

  The optional input title (character string) can be used to decorate the dialog caption.

  The optional argument icon selects a dialog icon. It can be one of `"none"` (default), `"error"`, `"help"`, or `"warn"`.

  The return value is always 1.

  Compatibility Note: The optional argument createmode is accepted for MATLAB compatibility, but is not implemented. A valid createmode is either one of the character strings `"nonmodal"`, `"modal"`, or `"replace"`, or a structure containing a field `"WindowStyle"` with one of the three character strings.

  Examples:

      msgbox ("Some message for the user.");
      msgbox ("Some message\nwith two lines.");
      msgbox ({"Some message", "with two lines."});
      msgbox ("Some message for the user.", "Fancy caption");

      % A message dialog box with error icon
      msgbox ("Some message for the user.", "Fancy caption", "error");

  See also: errordlg, helpdlg, inputdlg, listdlg, questdlg, warndlg.

: btn = questdlg (msg)
: btn = questdlg (msg, title)
: btn = questdlg (msg, title, default)
: btn = questdlg (msg, title, btn1, btn2, default)
: btn = questdlg (msg, title, btn1, btn2, btn3, default)

  Display msg using a question dialog box and return the caption of the activated button.

  The message may have multiple lines separated by newline characters ("\n"), or it may be a cellstr array with one element for each line.

  The optional title (character string) can be used to specify the dialog caption. It defaults to `"Question Dialog"`.

  The dialog may contain two or three buttons which will all close the dialog.

  The string default identifies the default button, which is activated by pressing the `ENTER` key. It must match one of the strings given in btn1, btn2, or btn3.

  If only msg and title are specified, three buttons with the default captions `"Yes"`, `"No"`, and `"Cancel"` are used.

  If only two button captions, btn1 and btn2, are specified the dialog will have only these two buttons.

  Examples:

      btn = questdlg ("Close Octave?", "Some fancy title", "Yes", "No", "No");
      if (strcmp (btn, "Yes"))
        exit ();
      endif

  See also: errordlg, helpdlg, inputdlg, listdlg, msgbox, warndlg.

: h = warndlg ()
: h = warndlg (msg)
: h = warndlg (msg, title)
: h = warndlg (msg, title, createmode)

  Display a warning dialog box with warning message msg and caption title.

  The default warning message is `"This is the default warning string."` and the default caption is `"Warning Dialog"`.

  The warning message may have multiple lines separated by newline characters ("\n"), or it may be a cellstr array with one element for each line.

  The return value h is always 1.

  Compatibility Note: The optional argument createmode is accepted for MATLAB compatibility, but is not implemented. See `msgbox` for details.

  Examples:

      warndlg ("Some warning text for the user.");
      warndlg ("Some warning text\nwith two lines.");
      warndlg ({"Some warning text", "with two lines."});
      warndlg ("Some warning text for the user.", "Fancy caption");

  See also: errordlg, helpdlg, inputdlg, listdlg, msgbox, questdlg.

For creating new dialog types, there is a dialog function.

: h = dialog (…, "property", value, …)

  Create an empty modal dialog window that other uicontrols can be added to.

  The dialog box is a figure object with properties as recommended for a dialog box.

  The default properties differing from a figure are:

  buttondownfcn

    `if isempty(allchild(gcbf)), close(gcbf), end`

  colormap

    []

  color

    defaultuicontrolbackgroundcolor

  dockcontrols

    off

  handlevisibility

    callback

  integerhandle

    off

  inverthardcopy

    off

  menubar

    none

  numbertitle

    off

  paperpositionmode

    auto

  resize

    off

  visible

    on

  windowstyle

    modal

  Multiple property-value pairs may be specified for the dialog object, but they must appear in pairs.

  The return value h is a graphics handle to the created figure. object.

  Examples:

      % create an empty dialog window titled 'Dialog Example'
      h = dialog ("name", "Dialog Example");

      % create a button (default style)
      b = uicontrol (h, "string", "OK", "position",[10 10 150 40], "callback","delete(gcf)");

      % wait for dialog to resume or close
      uiwait (h);

  See also: figure, uiwait.

Next: Progress Bar, Up: GUI Development [Contents][Index]