Navigation

Operators and Keywords

Function List:

C++ API

: 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.

Demonstration 1

The following code

 disp ('- test inputdlg with prompt and caption only.');
 prompt = {'Width', 'Height', 'Depth'};
 dims = inputdlg (prompt, 'Enter Box Dimensions');
 if (isempty (dims))
   helpdlg ('Canceled by user', 'Information');
 else
   volume  = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3});
   surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ...
                  str2num (dims{2}) * str2num (dims{3}) + ...
                  str2num (dims{1}) * str2num (dims{3}));
   helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', ...
                     volume, surface), 'Box Dimensions');
 endif

Produces the following output

- test inputdlg with prompt and caption only.

Demonstration 2

The following code

 disp ('- test inputdlg with prescribed scalar (2 lines per text field) and defaults.');
 prompt = {'Width', 'Height', 'Depth'};
 default = {'1.1', '2.2', '3.3'};
 rc = 2;
 dims = inputdlg (prompt, 'Enter Box Dimensions', rc, default);
 if (isempty (dims))
   helpdlg ('Canceled by user', 'Information');
 else
   volume  = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3});
   surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ...
                  str2num (dims{2}) * str2num (dims{3}) + ...
                  str2num (dims{1}) * str2num (dims{3}));
    helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', ...
                      volume, surface), 'Box Dimensions');
 endif

Produces the following output

- test inputdlg with prescribed scalar (2 lines per text field) and defaults.

Demonstration 3

The following code

 disp ('- test inputdlg with prescribed vector [1,2,3] for # of lines per text field and defaults.');
 prompt = {'Width', 'Height', 'Depth'};
 default = {'1.10', '2.10', '3.10'};
 rc = [1,2,3];  % NOTE: must be an array
 dims = inputdlg (prompt, 'Enter Box Dimensions', rc, default);
 if (isempty (dims))
   helpdlg ('Canceled by user', 'Information');
 else
   volume  = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3});
   surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ...
                  str2num (dims{2}) * str2num (dims{3}) + ...
                  str2num (dims{1}) * str2num (dims{3}));
   helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', ...
                     volume, surface), 'Box Dimensions');
 endif

Produces the following output

- test inputdlg with prescribed vector [1,2,3] for # of lines per text field and defaults.

Demonstration 4

The following code

 disp ('- test inputdlg with prescribed row by column sizes and defaults.');
 prompt = {'Width', 'Height', 'Depth'};
 default = {'1.10', '2.20', '3.30'};
 rc = [1,10; 2,20; 3,30];  % NOTE: must be an array
 dims = inputdlg (prompt, 'Enter Box Dimensions', rc, default);
 if (isempty (dims))
   helpdlg ('Canceled by user', 'Information');
 else
   volume  = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3});
   surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ...
                  str2num (dims{2}) * str2num (dims{3}) + ...
                  str2num (dims{1}) * str2num (dims{3}));
   helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', ...
                     volume, surface), 'Box Dimensions');
 endif

Produces the following output

- test inputdlg with prescribed row by column sizes and defaults.

Demonstration 5

The following code

 disp ('- test inputdlg with vector for a single item.');
 prompt = {'enter x value'};
 default = {1};
 answer = inputdlg (prompt,'Enter value', [1 10], default);
 if (isempty (answer))
   helpdlg ('Canceled by user', 'Information');
 else
   helpdlg (sprintf ('answer = %d', str2num(answer{1})), 'answer');
 endif

Produces the following output

- test inputdlg with vector for a single item.

Package: octave