File Exchange Pick of the Week

Our best user submissions

Input Dialog Box on Steroids

Jiro's pick this week is inputsdlg by Kesh.

This is pretty cool. There are quite a few different types of predefined dialog boxes within MATLAB. I use them quite often, and they serve my needs with the ability to customize them. But here comes the ultimate out-of-the-box dialog box utility. It combines all of the predefined ones into one and comes with a slew of customization capabilities.

The basic syntax is the same as inputdlg:

prompt = {'Enter the matrix size for x^2:';'Enter the colormap name:'};
name = 'Input for Peaks function';
answer = inputsdlg(prompt, name);

But then I can start going crazy with some of the customizations:

formats = struct('type', {}, 'style', {}, 'items', {}, ...
  'format', {}, 'limits', {}, 'size', {});
formats(1,1).type   = 'edit';
formats(1,1).format = 'integer';
formats(1,1).limits = [1 50];

formats(2,1).type   = 'list';
formats(2,1).style  = 'popupmenu';
formats(2,1).items  = {'jet', 'hsv', 'hot', 'cool', 'spring', 'summer', ...
  'autumn', 'winter', 'gray', 'bone', 'copper', 'pink', 'lines'};
defaultanswer = {20, 2};

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

Here are a few things that I really like about this entry:

  • Extensive HELP. It follows a standard MATLAB file help structure seen in MathWorks files.
  • Data validation. It allows you to restrict data type and value ranges for each field.
  • Auto resizing. It allows auto resizing of the fields when you resize the dialog box.
  • Structure as output. Rather than getting the answers as a cell array, you can have it return the output as a structure with appropriate field names.

Happy Holidays to all the MATLAB users out there! Thanks for reading our blog this year, and we'll see you all next year on New Year's Day!


Published with MATLAB® 7.9

  • print


To leave a comment, please click here to sign in to your MathWorks Account or create a new one.