{"id":2510,"date":"2009-12-25T13:59:22","date_gmt":"2009-12-25T13:59:22","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2009\/12\/25\/input-dialog-box-on-steroids\/"},"modified":"2017-01-06T21:26:08","modified_gmt":"2017-01-07T02:26:08","slug":"input-dialog-box-on-steroids","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2009\/12\/25\/input-dialog-box-on-steroids\/","title":{"rendered":"Input Dialog Box on Steroids"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/25862-inputsdlg--enhanced-input-dialog-box\"><tt>inputsdlg<\/tt><\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/36665\">Kesh<\/a>.\r\n   <\/p>\r\n   <p>This is pretty cool. There are quite a few different types of <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/f16-6011seg09.html#f16-8026\">predefined dialog boxes<\/a> within MATLAB. I use them quite often, and they serve my needs with the ability to customize them. But here comes the ultimate\r\n      out-of-the-box dialog box utility. It combines all of the predefined ones into one and comes with a slew of customization\r\n      capabilities.\r\n   <\/p>\r\n   <p>The basic syntax is the same as <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/inputdlg.html\"><tt>inputdlg<\/tt><\/a>:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">prompt = {<span style=\"color: #A020F0\">'Enter the matrix size for x^2:'<\/span>;<span style=\"color: #A020F0\">'Enter the colormap name:'<\/span>};\r\nname = <span style=\"color: #A020F0\">'Input for Peaks function'<\/span>;\r\nanswer = inputsdlg(prompt, name);<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/inputsdlg_dialog1.png\"> <\/p>\r\n   <p>But then I can start going crazy with some of the customizations:<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">formats = struct(<span style=\"color: #A020F0\">'type'<\/span>, {}, <span style=\"color: #A020F0\">'style'<\/span>, {}, <span style=\"color: #A020F0\">'items'<\/span>, {}, <span style=\"color: #0000FF\">...<\/span>\r\n  <span style=\"color: #A020F0\">'format'<\/span>, {}, <span style=\"color: #A020F0\">'limits'<\/span>, {}, <span style=\"color: #A020F0\">'size'<\/span>, {});\r\nformats(1,1).type   = <span style=\"color: #A020F0\">'edit'<\/span>;\r\nformats(1,1).format = <span style=\"color: #A020F0\">'integer'<\/span>;\r\nformats(1,1).limits = [1 50];\r\n\r\nformats(2,1).type   = <span style=\"color: #A020F0\">'list'<\/span>;\r\nformats(2,1).style  = <span style=\"color: #A020F0\">'popupmenu'<\/span>;\r\nformats(2,1).items  = {<span style=\"color: #A020F0\">'jet'<\/span>, <span style=\"color: #A020F0\">'hsv'<\/span>, <span style=\"color: #A020F0\">'hot'<\/span>, <span style=\"color: #A020F0\">'cool'<\/span>, <span style=\"color: #A020F0\">'spring'<\/span>, <span style=\"color: #A020F0\">'summer'<\/span>, <span style=\"color: #0000FF\">...<\/span>\r\n  <span style=\"color: #A020F0\">'autumn'<\/span>, <span style=\"color: #A020F0\">'winter'<\/span>, <span style=\"color: #A020F0\">'gray'<\/span>, <span style=\"color: #A020F0\">'bone'<\/span>, <span style=\"color: #A020F0\">'copper'<\/span>, <span style=\"color: #A020F0\">'pink'<\/span>, <span style=\"color: #A020F0\">'lines'<\/span>};\r\ndefaultanswer = {20, 2};\r\n\r\n[answer, canceled] = inputsdlg(prompt, name, formats, defaultanswer);<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/inputsdlg_dialog2.png\"> <\/p>\r\n   <p>Here are a few things that I really like about this entry:<\/p>\r\n   <div>\r\n      <ul>\r\n         <li><b>Extensive HELP<\/b>. It follows a standard MATLAB file help structure seen in MathWorks files.\r\n         <\/li>\r\n         <li><b>Data validation<\/b>. It allows you to restrict data type and value ranges for each field.\r\n         <\/li>\r\n         <li><b>Auto resizing<\/b>. It allows auto resizing of the fields when you resize the dialog box.\r\n         <\/li>\r\n         <li><b>Structure as output<\/b>. Rather than getting the answers as a cell array, you can have it return the output as a structure with appropriate field\r\n            names.\r\n         <\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   \r\n   <p>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\r\n      New Year's Day!\r\n   <\/p>\r\n   <p><a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2510#respond\">Comments<\/a>?\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_277f34e81167452a9adbc9ef8e46285e() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='277f34e81167452a9adbc9ef8e46285e ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 277f34e81167452a9adbc9ef8e46285e';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Jiro Doke';\r\n        copyright = 'Copyright 2009 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_277f34e81167452a9adbc9ef8e46285e()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.9<br><\/p>\r\n<\/div>\r\n<!--\r\n277f34e81167452a9adbc9ef8e46285e ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\r\n% Jiro>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/25862-inputsdlg--enhanced-input-dialog-box\r\n% |inputsdlg|> by \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/36665\r\n% Kesh>.\r\n%\r\n% This is pretty cool. There are quite a few different types of\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/f16-6011seg09.html#f16-8026\r\n% predefined dialog boxes> within MATLAB. I use them quite often, and they\r\n% serve my needs with the ability to customize them. But here comes the\r\n% ultimate out-of-the-box dialog box utility. It combines all of the\r\n% predefined ones into one and comes with a slew of customization\r\n% capabilities.\r\n%\r\n% The basic syntax is the same as\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/inputdlg.html\r\n% |inputdlg|>:\r\n\r\nprompt = {'Enter the matrix size for x^2:';'Enter the colormap name:'};\r\nname = 'Input for Peaks function';\r\nanswer = inputsdlg(prompt, name);\r\n\r\n%%\r\n% <<inputsdlg_dialog1.png>>\r\n%\r\n% But then I can start going crazy with some of the customizations:\r\n\r\nformats = struct('type', {}, 'style', {}, 'items', {}, ...\r\n  'format', {}, 'limits', {}, 'size', {});\r\nformats(1,1).type   = 'edit';\r\nformats(1,1).format = 'integer';\r\nformats(1,1).limits = [1 50];\r\n\r\nformats(2,1).type   = 'list';\r\nformats(2,1).style  = 'popupmenu';\r\nformats(2,1).items  = {'jet', 'hsv', 'hot', 'cool', 'spring', 'summer', ...\r\n  'autumn', 'winter', 'gray', 'bone', 'copper', 'pink', 'lines'};\r\ndefaultanswer = {20, 2};\r\n\r\n[answer, canceled] = inputsdlg(prompt, name, formats, defaultanswer);\r\n\r\n%%\r\n% <<inputsdlg_dialog2.png>>\r\n%\r\n% Here are a few things that I really like about this entry:\r\n%\r\n% * *Extensive HELP*. It follows a standard MATLAB file help structure\r\n% seen in MathWorks files.\r\n% * *Data validation*. It allows you to restrict data type and value ranges\r\n% for each field.\r\n% * *Auto resizing*. It allows auto resizing of the fields when you resize\r\n% the dialog box.\r\n% * *Structure as output*. Rather than getting the answers as a cell array,\r\n% you can have it return the output as a structure with appropriate field\r\n% names.\r\n%\r\n% Here's an example that shows the full capability of this utility. Kesh\r\n% includes the code that generates this dialog box. (click on the image to\r\n% see it in full size).\r\n%\r\n% <html>\r\n% <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fx_files\/25862\/6\/inputsdlg_demo.png\">\r\n% <img decoding=\"async\" src=\"https:\/\/www.mathworks.com\/matlabcentral\/fx_files\/25862\/6\/inputsdlg_demo.png\" width=\"450px\">\r\n% <\/a>\r\n% <\/html>\r\n%\r\n% Happy Holidays to all the MATLAB users out there! Thanks for reading our\r\n% blog this year, and we'll see you all next year on New Year's Day!\r\n%\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2510#respond Comments>?\r\n##### SOURCE END ##### 277f34e81167452a9adbc9ef8e46285e\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Jiro's pick this week is inputsdlg by Kesh.\r\n   \r\n   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... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2009\/12\/25\/input-dialog-box-on-steroids\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2510"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2510"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2510\/revisions"}],"predecessor-version":[{"id":8330,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2510\/revisions\/8330"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}