File Exchange

image thumbnail

inputsdlg: Enhanced Input Dialog Box

version (32.8 KB) by Kesh Ikuma
Predefined dialog box function to accept user inputs of several forms


Updated 30 Jun 2015

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

This function is an enhanced version of the standard INPUTDLG function with many additional features:
- 8 control types: text, edit, check, list, range, color, table, button
(**color, table, and button were added in v2.0**)
- Text Type is a static text (e.g., to place an instruction)
- Check Type displays a checkbox with a label, returns one of two values. Value could be logical, integer, or string
- Edit Type can be configured to accept:
* plain text (single- or multi-line mode)
* date (following date formats as defined in DATESTR)
* numeric value (integer or float with attribute specification)
* file or directory name (with UIGETFILE, UIPUTFILE, or UIGETDIR functions, supports UIGETFILE multi-sel
ect mode)
* vector (can specify the length of the vector or the attributes of its elements if the length is fixed or arbitrary). To specify a row vector, include the 'row' keyword in formats.limits field.
- List Type returns index(es) of the selected item and can have 4 different appearances:
* Popupmenu
* Listbox (can be made to multi-select)
* Radiobutton (button placements can be customized)
* Togglebutton (button placements can be customized)
- INPUTSDLG can automatically size controls and dialog box for an optimal appearance, and control's size can be made to auto-adjust if dialog is made resizable.
- INPUTSDLG supports user callbacks to all UI controls as well as dialog's CreateFcn and DeleteFcn callbacks. The callback function takes additional input arguments to standard MATLAB callback arguments.
- INPUTSDLG returns the user entries in a cell or in a structure
- INPUTSDLG is backward compatible with INPUTDLG except for its returned values when canceled. With default answers given, INPUTDLG returns an empty cell while INPUTSDLG returns the default answers. INPUTSDLG returns the second parameter, CANCELED(a logical flag) to indicate how the dialog box is terminated.
- Luke Reisner prepared v1.3 and kindly shared his modification/bug fixes.
- Florian Hatz initiated the development of v2.0 with his ideas of adding table, color, and tiling option

Cite As

Kesh Ikuma (2021). inputsdlg: Enhanced Input Dialog Box (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (64)



i'm having performance issues with this now. i'm on 2019b, and most of the time when I click "ok" or whatever it's named for my dialog box, matlab beachballs. i'd love some advice on how to solve this problem.

LIU Likun

Andrew Diamond

Slight issue - if a user types an invalid number in an edit box (with validation number limits) but immediately presses the inputdlg's OK button (vs hitting enter or going to another field) , thinking it was valid, the edit field will automatically be set to the (lower) valid number, the error box for an invalid number will appear, and then the after the user presses OK to make the errordlg go away, the inputsdlg box will go away too (due to pressing the inputsdlg OK button before they were informed of the error). I would imagine the correct behavior would be as if the user pressed anything else but OK on the inputsdlg.

Kat Lee

Great function.
But the decimal is only round to 4 digits after decimal dot, is it predefined inside the function or is there anyway we could extend the decimal number rounding precision for more digits

Mohammed Alabkari

Ehsan Asadi

Is there a simpler version of the great job that shows how to use only two of different inputs types in a dialog box? This file is a bit complicated to understand!


Rohan Maharjajn

very nice!! thank you!!

Michael Fitzpatrick

I'm using 2016b and trying to create a GUI that varies in size, sometimes instantiating larger than my screen size. How would you add a test to see if the GUI is larger than the screen size and if so add scroll bars on appropriate axes?

Any help is most appreciated.


Is it possible to tag the created controls? Something like formats(1,1).tag = 'ThisButtonTag'; ???


Great code btw.

dan brake

formerly a 5-star rating from me, but getting text is broken for me in 2016a. maybe earlier versions, but i know my code worked as late as 2014b. If i generate a text box with default value, inputsdlg just writes immediately over my entry. similarly, if I try to use selection-lists to select one of many options, it simply closes the selection list early.

i made a video of these two problems, on youtube:

edit a few hours later: the cause is a text field before other editable fields. the following code replicates the problem:

prompt(1,:) = {'some text',[],[]};
formats(1).type = 'text';% = struct('type','edit','format','integer','limits',[1 inf]);

prompt(2,:)={'Enter the matrix size for x^2:','asdf',[]};
name='Input for Peaks function';

formats(2,1).type = 'edit';
formats(2,1).format = 'integer';
formats(2,1).limits = [1 inf];

defaultanswer.asdf = 20;

[answer,canceled] = inputsdlg(prompt,name,formats,defaultanswer);

an easy workaround i think is to not put a text field first?

Chris Rodgers

Pressing SPACE when a checkbox is highlighted should select/deselect the checkbox but at present it closes the dialog.

This can be fixed by adding this below line 860:

if ~isempty(findobj(gco,'flat','type','uicontrol','style','checkbox')) && I==2 % space

Kesh Ikuma

@Romain - Pressing the space bar is equivalent to pressing "OK" button. It somehow did not occur to me that it interferes with spaces in textboxes. For a quick workaround, you can remove "'space'," from Line 797.



great tool you have created here. My only reserve for the moment is that it seems to sometimes suffer of instability. I give you a concrete example: the 'space' bar seems to be often understood as a 'cancel' or 'escape' button when the dialog window is used. For instance, in the following example (taken from my work), I create a 10*2 table of characters.

Yet, if I try to type a space while writing in one of the entries, the dialog box will close immediately and the entry in which I was typing will be reported as empty.

Here is the code:


endo={'RGDP' 'EONIA'}

% initiate the interface
title7='Conditional forecasts';

% create Table
tabletype={'char' 'char'};

formats7(7,1).size=[185 202];

% display the interface


Any idea of this reason? Could my Matlab version (R2012b) be the problem? This 'space issue' happened a couple of other times while using the function. Also, I sometimes faced requests to fill "required" boxes on which the required option had not been activated.

So, some issues may remain to be fixed. Overall, fantastic work though, helped me a lot to design my GUI. Thanks a lot!


I was noticing that inputsdlg is slower in 2014b. After investigating, I added

set(gcf, 'Renderer', 'painters')

right before drawnow inside inputsdlg. It's now just as fast as 2014a. This turns off OpenGL rendering of course, but only temporarily.

This is a very helpful tool. Thanks!

Kesh Ikuma

@Spigge - All edit box formats with dialog prompts are implemented with uicontrol's ButtonDownFcn (instead of Callback) and Enable='inactive'. So, in order for you to toggle the dir edit box Enable state, you need to do the following:

From Enabled -> Disabled
1. Save dir edit's ButtonDownFcn (I usually use the edit's UserData property)
2. Set edit's Enable to 'off' and ButtonDownFcn to [] (and UserData with the callback function)

From Disabled->Enabled
1. Retrieve the saved ButtonDownFcn callback
2. Set edit's Enable to 'inactive' and reinstate ButtonDownFcn

Hope this helps


Hi Kesh,

I have created a check box that controls the enable state of an edit text box with the format 'dir'. The edit box is initially disabled (grayed) and gets enabled (white) when the check box is checked and back to disabled when the check box is unchecked. So far so good. The problem is that the default behaviour of the edit box on mouse click, which is to open a file dialog (via UIGETDIR) and then display the selected directory as a string in the edit box, is lost when disabled and enabled this way. Instead it behaves like a normal edit box of format 'text'. Why does this happen and how can I get it to work properly you think?




Hello Kesh,
great tool...
something went wrong with my last submission...
I think there is an error with the tooltips on line 1070: changed Prompt(:,3) to Prompt(:,4)
I also added the following line (2293) to have tooltips for all elements:
% style-dependent configuration



I added the following in line 2293:
% style-dependent configuration
set(hc,'TooltipString',TooltipStrings{m}); % added


Jonathan Lister

Enables quick scripting of non standard dialogs. I used to have to do these by hand. Thanks for the tool.


Cool, got it working now! Thanks for your help and for making a great program.

Kesh Ikuma

@Dan - Yeah, that error message is awfully cryptic and so ESL, isn't it? Sorry about that (it'll be improved in the next upload). It's telling you that the number of Formats elements do not match the number of Prompt rows. Here is how I modified your inputsdlg line to make it run:

[Answer,Cancelled] = inputsdlg(Prompt,Title,Formats(1:3),rmfield(DefAns,'DataFolder'),Options);

The dimensions of Prompt, Formats, and DefAns inputs are critical for this function to run. If you are creating a "dense" dialog (i.e., w/o any empty prompt cell), the number of rows of Prompt must match the number of elements of Formats, and DefAns' fields must exactly account for all the second column of Prompt array.

Good luck! -Kesh


Dear Kesh,
This looks like an awesome tool. However, I can't seem to get it to work in my program. I am getting the following error message:

Error using inputsdlg (line 397)
Not enough FORMATS size for the display.

I don't understand what this error means and would be grateful for your advice. Here's my code (modeled on the demo file you provided):

%%%% Options Dialog Box using inputsdlg
Title = 'Program Options';
Options.Resize = 'on';
Options.Interpreter = 'tex';
Options.CancelButton = 'on';
Options.ApplyButton = 'on';
Options.ButtonNames = {'Continue','Cancel'}; %<- default names, included here just for illustration
Option.Dim = 1; % Horizontal dimension in fields
Prompt = {};
Formats = {};
DefAns = struct([]);

Prompt(1,:) = {'Choose program options',[]};
Formats(1).type = 'text';

Prompt(2,:) = {'Process traces with Chung-Kennedy filter prior to counting steps?','CKfilt'};
Formats(2).type = 'check';
DefAns(1).CKfilt = true;

Prompt(3,:) = {'Apply intensity filter to discard small steps?','IntFilt'};
Formats(3).type = 'check';
DefAns.IntFilt = true;

Prompts(4,:) = {'Select folder containig data to analyze','DataFolder'};
Formats(4).type = 'edit';
Formats(4).format = 'dir';
Formats(4).required = 'on';
DefAns.DataFolder = [];

[Answer,Cancelled] = inputsdlg(Prompt,Title,Formats,DefAns,Options);
%%%% End of dialog box

Kesh Ikuma

@John - I'm glad it's working for you now. Now, re: enable/disable other control, here is how I would do it.

First, create an m-function:

function toggleEnable(hctl,htgt)

if get(hctl,'Value')

and set the callback of the controlling checkbox (located at (2,4)) as

Formats(2,4).callback = @(hobj,~,h,k)toggleEnable(hobj,h(k+1,1));

The above assumes that the checkbox controls the enable state of h(k+1,1) control, i.e., the control immediately after the checkbox. Note that one checkbox can en/disable multiple controls if you desire.


Nvm, I was able to get a solution (it might not be the prettiest, but it works :-) ).

For other's future reference I will explain what I did. In Kesh's inputsdlg_demo.m file I added the following lines of code after prompt 5:


EnableCheck = {'on','off'};


Formats(2,4).callback = @(~,~,h,k)set(h(k+1), 'enable', EnableCheck{EnableDisable(x)});


And I called I simple function that I wrote (titled EnableDisable). I have included that code below:

% enable/disable controls associated with (some) % checkboxes
function x = EnableDisable(x)

global x

x = (a+b)-x;



I know that this is probably not the best way to go about it, but it does work if anyone is interested.


@Kesh, Thanks again for this awesome function! Your updates are working great!

I am actually interested in doing what I think your "Enable enhanced mode" checkbox is supposed to be doing. I am assuming that what you were thinking about doing here is creating a callback function that then Enables/Disables a different Prompt. However, it appears that you haven't included your callback function. So, right now it is just a checkbox.

I am currently working to add this callback to my current dialog box. But, I thought if you already had it completed then it could save me some work if you wouldn't mind sharing it. :-)

Erasmo Morales

@Ikuma: Thank you sir, you are a good person. This new version works on Windows now. :) I will experiment with it this weekend. I will send you and email if I have more troubles.

Thanks again!

Kesh Ikuma

@Erasmo - The reported compatibility bug for pre-R2013a has been fixed in v2.0.2, which I just uploaded.

Kesh Ikuma

@Erasmo - Your issue has been confirmed on R2012b. I will look into it in a next couple days. Please keep your eyes for the next update.

Re: slider. Only way for you to customize the v1.3 slider behavior is to hack the code. The slider callback is set on Line 1245 to an anonymous function. You need to replace the function with a custom callback to modify the unit label. The handle of the unit label is given in handles struct, in the main inputsdlg scopes. Recommend using a nested function.

Erasmo Morales

@Ikuma, thanks for replying. I am using Matlab on Windows. I've just tried v2.0.1 and it does the same.

About the slider:
For now, on a project I am using the older version of inputsdlg v1.3. Is what you suggested available in this version?

Kesh Ikuma

@Erasmo - I will see if I can reproduce those errors that you reported. These demo scripts work fine on my system. Are you running Matlab on Mac or Linux?

As for showing the value of the slider, you can use the slider callback to modify either its TooltipString or the "unit" label. If you aren't sure how to do this, shoot me an email.

Erasmo Morales

Hello, Mr. Ikuma. I am having similar troubles that John is having.

When running inputsdlg_demo.m I get:

Error using inputsdlg (line 394)
Default integer data must integer.

Error in inputsdlg_demo (line 187)
[Answer,Cancelled] = inputsdlg(Prompt,Title,Formats,DefAns,Options)

When running inputsdlg_demo_tile.m I get:

Error using inputsdlg (line 394)
Default dir must be a valid path.

Error in inputsdlg_demo_tile (line 57)

What do I have to change to get these to run? I am using Matlab 2012b.

Also, is there a way to display what value the slider has(for the range type)?

0 100
|---[]------| (40)
I would like to display this value (40).

Thank you.

Kesh Ikuma

@John - Thanks for the bug report. I just uploaded the fixed version (v2.0.1) to (re)enable 'inputsdlg' style input arguments.


This looks like a great tool!

However, I appear to be unable to run the demos or the examples shown in the "File Exchange Pick of the Week".
I am getting a variety of errors such as:

Error 1 (1st example in "File Exchange Pick of the Week"):

Error using struct
Field names must be strings.

Error in inputsdlg>checkformats (line 1086)
Formats = repmat(struct(fields{:}),NumQuest,1);

Error in inputsdlg (line 388)
[Formats,err] = checkformats(Formats,NumQuest,FormatDefaultFields);

Error 2 (2nd example in "File Exchange Pick of the Week"):

Error using inputsdlg (line 394)
Default text data format must be char.

Error 3 (attempt to run inputsdlg_demo_tile.m)

Error using inputsdlg (line 394)
Default dir must be a valid path.

Error in inputsdlg_demo_tile (line 57)

Error 4 (attempt to run inputsdlg_demo.m):

Error using inputsdlg (line 394)
Default integer data must integer.

Error in inputsdlg_demo (line 187)
[Answer,Cancelled] = inputsdlg(Prompt,Title,Formats,DefAns,Options)

However, the inputsdlg_demo_contactinfo.m works great! I know that I have included a lot of info here, but I thought that you might be able to investigate this better with more information.

Kesh Ikuma

@Charles - Great idea! I'm working on a new version as of now. I will incorporate your suggestion in the upcoming release.

Charles Collin

This looks like a very useful tool. However, I noted that it has the same issue regarding font size as does inputdlg. That is, it only takes the factory default, making it impossible to change the size of the font using (e.g.) set(0, 'DefaultTextFontSize', 14), as is possible for most of the other "dlg" commands. I modified the script at line 940 to read:
'FontSize' get(0,'DefaultTextFontSize');
This makes it accept the user-definable default, but the size of the text boxes don't scale accordingly. It would be great if an updated version of the function could do this. Thanks for your attention.


Perfect tool, I like it a lot

Soren Preus

Invaluable when making large GUI-based applications!

Kesh Ikuma

@kirka - oops, I wrote you a reply before to Troy, but FEX comment section acted up and overwrote my reply to you.

That being said, the only way for this function to return the answers before closing the dialog is for you to modify the code yourself. I modeled this function after the built-in inputdlg function, which is uses a modal window.


I'm not used to read other ones code so I don't know how to change callbacks in a way that I'm looking for. Like I earlier wrote I want to make apply button to set my answers without closing the dialog (like pressing ok but dialog stays open).

Hopefully someone understood my problem so I can get even some sort of an answer.

Kesh Ikuma

@Troy - I think the answer to your question is 'yes'. The number of field is determined by the size of PROMPT (cell array) argument (and others) so you can programatically modify PROMPT array size during run time. Hope this helps.

Troy Rockwood

This is a lifesaver! Is there a good way to have the number of fields be determined at run-time rather than before? I would like to have fields for n filenames where the user defines n. Thanks.



How I can get answers out from inputsdlg without closing the dialog window. I need it to work that way when I want to check things fast.

Is it possible to make apply button work like ok button without closing dialog window by changing callback, for example. Or any other way.

Felix Goldberg


This looks like a great tool and I'm sure i'll use it.

For now, though, I need just a simple thing which appears to be unaddressed: I want to create a dialog box - just like inputdlg - with an arbitrary number of buttons.

Do you know how one does that?


Kesh Ikuma

@Terry - Thanks for reporting the bug. I've confirmed it. Since I'm in a process of making a major update, this bug won't be fixed until v2.0 (there is v1.3 just submitted & pending for MathWorks approval) but here's how to fix it.

Replace the two if-else-end clauses that you posted above with the following:

if isempty(UserOptions) % no option specified, use default
err = {};
elseif ischar(UserOptions) && any(strcmpi(UserOptions,{'on','off'}))
% check if User Resize Option is given as on/off string
UserOptions.Resize = UserOptions;
elseif ~isstruct(UserOptions) && numel(UserOptions)~=1
err{2} = 'Options must be ''on'', ''off'', or a scalar struct.';

Let me know if you encounter any other bugs!

Terrance Nearey

Very nice. And thanks for revising.
I'm trying to write some preprocessors for inputsdlg and have been exercises many of its possibilities in testing the front end code.
I think I've come across a bug. in the call to checkcptions() following line 1535:

The first if-then-else group will fail if Options on input is 'on',
so second one will not be reached.
if isempty(UserOptions) % no option specified, use default
err = {};
elseif numel(UserOptions)~=1
err{2} = 'Options struct must be a scalar.';
if errdbg, disp('errdbg: Keyboarding'),sysbeep(2),dbstack, keyboard; end; return;

% check if User Resize Option is given as on/off string
if ischar(UserOptions) && strcmpi(UserOptions,{'on','off'})
UserOptions.Resize = UserOptions;
elseif ~isstruct(UserOptions)
err{2} = 'Options must be ''on'', ''off'', or a struct.';
if errdbg, disp('errdbg: Keyboarding'),sysbeep(2),dbstack, keyboard; end; return;
If your interested, I'll send you the front-ends when I've finished them
Thanks again,
Terry Nearey

Kesh Ikuma


I agree with your take on checkoptions(). I've scrapped the function and rewritten it in more-or-so of what you suggested. Also, this change made the user option field names to be case insensitive.

Hopefully, v1.2.2 just upped would fix all checkoptions() related bugs.

Jason Kaeding

Hi Kesh,

New bug for you. This is related to the last one I posted on 11 Jun. Because you modified the Fields to handle the cellstr correctly, the problem migrated to line 1653. I think this line should be changed to

Options.ButtonNames = Fields{2,6}{1};

Personally, I think that the way that this checkoptions function is coded is a little bit strange. If the user specifies a struct as the input, then the struct is not built until later. I think that the struct should be built at the top regardless (using an else), then only add the fields if the user specifies them. This would reduce the problems that you are having now because you are creating fields if they don't exist, but you already specified all of the default values anyway.


Kesh Ikuma


Thanks for the bug report. The fixed version has been uploaded (v.1.2.1).

As for the calender support, I'd like to keep this function completely standalone. So, unless there is a built-in function (either MATLAB or JAVA) for the calender dialog, I'll leave it as the text field. I have an idea to let you interface inputsdlg with external functions, but I'm a little too busy at this time to work on that.

Jason Kaeding

Hi Kesh,

I think there's a bug in v1.2. It seems you modified checkoptions a lot, but if I do not specify an option as input (nargin < 5), then I get the error "Options must be scalar."

This stems from when you call Options = struct(Fields{:}). Because the ButtonNames field is a cell, it deals these to a 1x3 struct. What you need to do is declare ButtonNames as a "double cell": {{'OK','Cancel','Apply'}}. This will put the inner cell into a signle struct element.

Jason Kaeding

Kesh, see UIGETDATE or UICALsubmissions as examples (or even use them directly).

Kesh Ikuma

@Nick, "active" control is an interesting one, and I think I can incorporate that fairly easily. I'll try to include it in the next version.

@Jason, Thanks for the bug report. I'll fix it in the next version. Also, 'date' format is a good one. ActiveX... not so sure as I've never used it myself. May be one of these days I'll learn.

Jason Kaeding

Hi Kesh,

I found a bug in line 295. You reference handles.Figure, but it appears handles.fig is the correct fieldname.


Jason Kaeding

Hi Kesh,

First, I wanted to say that this is a great submission. One suggestion: a 'date' format would be nice. Could even use the ActiveX calendar control, but at least a normal date validation option would be enough.



Awesome, just what I've needed for years. Just one suggestion: would it be possible to include another input argument (perhaps a logical array) that indicates whether each control is active or not. This way some controls could be "greyed out" or turned off on a particular dialog layout rather than having to create a new dialog layout whithout including those controls.

Brett Shoelson

Excellent work!


Good work! Could you suggest me some applications of this dialog box. I am new to Matlab and still learning many suffs.


Kesh Ikuma


The function was developed in r2008a; so, I am not surprised if it is not compatible with r14.

Since I do not have r14, there is no way for me to make inputsdlg compatible with r14 on my own. If you email me the errors that you are encountering, I can help you modifying the code.



I am having some troubles to run the package, may it be that I do not have the latest matlab release, I am running r14.


Andreas Greuer

This inputsdlg should be standard in matlab like the inputdlg. We will use it. Good job.

Mohammed El-Said

Great work,
it is really useful,

Kesh Ikuma


Thanks for the bug report (and I'm a little embarrassed by such blatant bugs in my very demo...).

I fixed the bugs, added a couple more features, and uploaded the updated files.

Andreas Greuer

The concept looks nice and quiet flexible.

But there are still some bugs in.
The Cancel is not indicated and gives just the default values back.
For an edit field comes not the text entered in the field, but a crazy structure (in the example the field "Name")
The answer gives back default instead of the new changed values. (in the example the field "SSN")

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!