You are on page 1of 3

inputdlg

Create and open input dialog box


Syntax
answer = inputdlg(prompt)
answer = inputdlg(prompt,dlg_title)
answer = inputdlg(prompt,dlg_title,num_lines)
answer = inputdlg(prompt,dlg_title,num_lines,defAns)
answer = inputdlg(prompt,dlg_title,num_lines,defAns,options)
Description
answer = inputdlg(prompt) creates a modal dialog box and returns user input for
multiple prompts in the cell array. prompt is a cell array containing prompt str
ings.
Note A modal dialog box prevents the user from interacting with other wi
ndows before responding. For more information, see WindowStyle in the MATLAB Fig
ure Properties.
answer = inputdlg(prompt,dlg_title) dlg_title specifies a title for the dialog b
ox.
answer = inputdlg(prompt,dlg_title,num_lines) num_lines specifies the number of
lines for each user-entered value. num_lines can be a scalar, column vector, or
matrix.
*
If num_lines is a scalar, it applies to all prompts.
*
If num_lines is a column vector, each element specifies the number of line
s of input for a prompt.
*
If num_lines is a matrix, it should be size m-by-2, where m is the number
of prompts on the dialog box. Each row refers to a prompt. The first column spec
ifies the number of lines of input for a prompt. The second column specifies the
width of the field in characters.
answer = inputdlg(prompt,dlg_title,num_lines,defAns) defAns specifies the defaul
t value to display for each prompt. defAns must contain the same number of eleme
nts as prompt and all elements must be strings.
answer = inputdlg(prompt,dlg_title,num_lines,defAns,options) If options is the s
tring 'on', the dialog is made resizable in the horizontal direction. If options
is a structure, the fields shown in the following table are recognized:
Field
Description
Resize
Can be 'on' or 'off' (default). If 'on', the window is resizable horizontally.
WindowStyle

Can be either 'normal' or 'modal' (default).


Interpreter
Can be either 'none' (default) or 'tex'. If the value is 'tex', the prompt strin
gs are rendered using LaTeX.
If the user clicks the Cancel button to close an inputdlg box, the dialog return
s an empty cell array:
answer =
{}
Remarks
inputdlg uses the uiwait function to suspend execution until the user responds.
The returned variable answer is a cell array containing strings, one string per
text entry field, starting from the top of the dialog box.
To convert a member of the cell array to a number, use str2num. To do this, you
can add the following code to the end of any of the examples below:
[val status] = str2num(answer{1}); % Use curly bracket for subscript
if ~status
% Handle empty value returned for unsuccessful conversion
% ...
end
% val is a scalar or matrix converted from the first input
Users can enter scalar or vector values into inputdlg fields; str2num converts s
pace- and comma-delimited strings into row vectors, and semicolon-delimited stri
ngs into column vectors. For example, if answer{1} contains '1 2 3;4 -5 6+7i', t
he conversion produces:
val = str2num(answer{1})
val =
1.0000
2.0000
3.0000
4.0000
-5.0000
6.0000 + 7.0000i
Example
Example 1
Create a dialog box to input an integer and colormap name. Allow one line for ea
ch value.
prompt = {'Enter matrix size:','Enter colormap name:'};
dlg_title = 'Input for peaks function';
num_lines = 1;
def = {'20','hsv'};
answer = inputdlg(prompt,dlg_title,num_lines,def);
Example 2
Create a dialog box using the default options. Then use the options to make it r
esizable and not modal, and to interpret the text using LaTeX.

prompt={'Enter the matrix size for x^2:',...


'Enter the colormap name:'};
name='Input for Peaks function';
numlines=1;
defaultanswer={'20','hsv'};
answer=inputdlg(prompt,name,numlines,defaultanswer);
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
answer=inputdlg(prompt,name,numlines,defaultanswer,options);
See Also
dialog, errordlg, helpdlg, listdlg, msgbox, questdlg, warndlg, input
figure, str2num, uiwait, uiresume
Predefined Dialog Boxes for related functions
Was this topic helpful?
USXY = Str2NUm(answer{1});
1984-2010 The MathWorks, Inc.

Terms of Use

Patents

Trademarks

Acknowledgments

You might also like