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:
A cell array with strings labeling each text field. This input is required.
String to use for the caption of the dialog. The default is
"Input Dialog"
.
Specifies the size of the text fields and can take three forms:
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.
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.
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.
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.
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.
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.
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