{"id":2580,"date":"2010-07-23T12:51:00","date_gmt":"2010-07-23T12:51:00","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2010\/07\/23\/automatic-progress-bar\/"},"modified":"2010-07-23T12:51:00","modified_gmt":"2010-07-23T12:51:00","slug":"automatic-progress-bar","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2010\/07\/23\/automatic-progress-bar\/","title":{"rendered":"Automatic Progress Bar"},"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\/28179-progress-bars\">Progress Bars<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/102114\">Richard S<\/a>. This was suggested by my co-worker <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32376\">Sarah Zaranek<\/a>, whom some of you may know from her guest <a href=\"https:\/\/blogs.mathworks.com\/loren\/2009\/10\/02\/using-parfor-loops-getting-up-and-running\/\">post<\/a> in Loren's <a href=\"https:\/\/blogs.mathworks.com\/loren\/\">blog<\/a>.\r\n   <\/p>\r\n   <p>What is it with our obsessions with <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=progress+bar\">progress bars<\/a>? You can see that there are quite a few File Exchange entries, and they all have their subtle differences in the way they\r\n      operate or are implemented. Bob highlighted one just recently in this <a href=\"https:\/\/blogs.mathworks.com\/pick\/2010\/05\/14\/progbar\/\">blog post<\/a>. I have to admit that I have written a couple of progress bars myself, and I think the joy I get from writing a progress\r\n      bar comes from the fact that it challenges me to think about both the usability of the tool, as well as the efficiency of\r\n      the code. Progress bars give useful information, but we don't want them to add extra overhead. That's where I'm drawn to.\r\n   <\/p>\r\n   <p>I did a double take when I saw this entry by Richard. He implemented everything using <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/matlab_oop\/ug_intropage.html\">MATLAB Classes<\/a> (introduced in R2008a), and it is very well commented (type <tt>doc Progress<\/tt>). His progress window is a JFrame, and you can have multiple progress bars. But what really impressed me was his \"automatic\r\n      code generation\" capability. Essentially, you can annotate your script using a special syntax, and it would automatically\r\n      add the boilerplate code to display the progress bars. For example, by placing <tt>\"%%p#\"<\/tt> at the for-loops you can tell <tt>Progress<\/tt> to interpret that as placing a progress bar.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">repetitions = 10;\r\n<span style=\"color: #0000FF\">for<\/span> rep=1:repetitions <span style=\"color: #228B22\">%%p1<\/span>\r\n   parameters_values = rand(1, 499);\r\n   <span style=\"color: #0000FF\">for<\/span> ex_index=1:numel(parameters_values) <span style=\"color: #228B22\">%%p2<\/span>\r\n      perform_test(parameters_values(ex_index));\r\n   <span style=\"color: #0000FF\">end<\/span> <span style=\"color: #228B22\">%%p2<\/span>\r\n<span style=\"color: #0000FF\">end<\/span> <span style=\"color: #228B22\">%%p1<\/span><\/pre><p>Then you can simply call the script with<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">prog(<span style=\"color: #A020F0\">'SCRIPT_NAME'<\/span>)<\/pre><p>And the progress bars will auto-magically show up!<\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/progressbar_screenshot.png\"> <\/p>\r\n   <p>Wow, very ingenious! Thanks, Richard, for a showing me something I haven't seen before.<\/p>\r\n   <p><b>Comments<\/b><\/p>\r\n   <p>Give it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2580#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/28179-progress-bars#comments\">comment<\/a> for Richard.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_b60108bbc2744d31923074f497f9680f() {\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='b60108bbc2744d31923074f497f9680f ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' b60108bbc2744d31923074f497f9680f';\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 2010 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_b60108bbc2744d31923074f497f9680f()\"><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.10<br><\/p>\r\n<\/div>\r\n<!--\r\nb60108bbc2744d31923074f497f9680f ##### 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\/28179-progress-bars\r\n% Progress Bars> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/102114\r\n% Richard S>. This was suggested by my co-worker\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32376 Sarah\r\n% Zaranek>, whom some of you may know from her guest\r\n% <https:\/\/blogs.mathworks.com\/loren\/2009\/10\/02\/using-parfor-loops-getting-up-and-running\/\r\n% post> in Loren's <https:\/\/blogs.mathworks.com\/loren\/ blog>.\r\n%\r\n% What is it with our obsessions with\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=progress+bar\r\n% progress bars>? You can see that there are quite a few File Exchange\r\n% entries, and they all have their subtle differences in the way they\r\n% operate or are implemented. Bob highlighted one just recently in this\r\n% <https:\/\/blogs.mathworks.com\/pick\/2010\/05\/14\/progbar\/ blog post>. I have\r\n% to admit that I have written a couple of progress bars myself, and I\r\n% think the joy I get from writing a progress bar comes from the fact that\r\n% it challenges me to think about both the usability of the tool, as well\r\n% as the efficiency of the code. Progress bars give useful information, but\r\n% we don't want them to add extra overhead. That's where I'm drawn to.\r\n%\r\n% I did a double take when I saw this entry by Richard. He implemented\r\n% everything using\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/matlab_oop\/ug_intropage.html\r\n% MATLAB Classes> (introduced in R2008a), and it is very well commented\r\n% (type |doc Progress|). His progress window is a JFrame, and you\r\n% can have multiple progress bars. But what really impressed me was his\r\n% \"automatic code generation\" capability. Essentially, you can annotate\r\n% your script using a special syntax, and it would automatically add the\r\n% boilerplate code to display the progress bars. For example, by placing\r\n% |\"%%p#\"| at the for-loops you can tell |Progress| to interpret that as\r\n% placing a progress bar.\r\n\r\nrepetitions = 10;\r\nfor rep=1:repetitions %%p1\r\n   parameters_values = rand(1, 499);\r\n   for ex_index=1:numel(parameters_values) %%p2\r\n      perform_test(parameters_values(ex_index));\r\n   end %%p2\r\nend %%p1\r\n\r\n%%\r\n% Then you can simply call the script with\r\n\r\nprog('SCRIPT_NAME')\r\n\r\n%%\r\n% And the progress bars will auto-magically show up! \r\n%\r\n% <<progressbar_screenshot.png>>\r\n%\r\n% Wow, very ingenious! Thanks, Richard, for a showing me something I\r\n% haven't seen before.\r\n%\r\n% *Comments*\r\n%\r\n% Give it a try and let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2580#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/28179-progress-bars#comments\r\n% comment> for Richard.\r\n\r\n##### SOURCE END ##### b60108bbc2744d31923074f497f9680f\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Jiro's pick this week is Progress Bars by Richard S. This was suggested by my co-worker Sarah Zaranek, whom some of you may know from her guest post in Loren's blog.\r\n   \r\n   What is it with our... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2010\/07\/23\/automatic-progress-bar\/\">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\/2580"}],"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=2580"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2580\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}