{"id":2595,"date":"2016-08-17T08:03:10","date_gmt":"2016-08-17T13:03:10","guid":{"rendered":"https:\/\/blogs.mathworks.com\/videos\/?p=2595"},"modified":"2017-05-22T14:34:24","modified_gmt":"2017-05-22T19:34:24","slug":"displaying-progress-status-of-long-running-script-part-4-display-erase-utility","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/videos\/2016\/08\/17\/displaying-progress-status-of-long-running-script-part-4-display-erase-utility\/","title":{"rendered":"Displaying Progress Status of Long Running Script, Part 4: Display-Erase Utility"},"content":{"rendered":"<p>Sometimes when displaying the progress of a long running script, there is so much output at the command window that there is too much to scroll through or the buffer fills up and you can&#8217;t go back to see full the history.<\/p>\n<p>In this <a href=\"https:\/\/blogs.mathworks.com\/videos\/2015\/10\/29\/matlab-code-along-videos\/\">code-along<\/a> style video I write a utility, based on my colleague Sean&#8217;s suggestion that displays new status information after erasing the previous information. This allows progress to displayed without filling up the command window. <\/p>\n<p>Features used in this video include:<\/p>\n<ul>\n<li>Displaying characters and strings<\/li>\n<li>Storing state with nested functions<\/li>\n<\/ul>\n<p><div class=\"row\"><div class=\"col-xs-12 containing-block\"><div class=\"bc-outer-container add_margin_20\"><videoplayer><div class=\"video-js-container\"><video data-video-id=\"5443941528001\" data-video-category=\"blog\" data-autostart=\"false\" data-account=\"62009828001\" data-omniture-account=\"mathwgbl\" data-player=\"rJ9XCz2Sx\" data-embed=\"default\" id=\"mathworks-brightcove-player\" class=\"video-js\" controls><\/video><script src=\"\/\/players.brightcove.net\/62009828001\/rJ9XCz2Sx_default\/index.min.js\"><\/script><script>if (typeof(playerLoaded) === 'undefined') {var playerLoaded = false;}(function isVideojsDefined() {if (typeof(videojs) !== 'undefined') {videojs(\"mathworks-brightcove-player\").on('loadedmetadata', function() {playerLoaded = true;});} else {setTimeout(isVideojsDefined, 10);}})();<\/script><\/div><\/videoplayer><\/div><\/div><\/div><\/p>\n<p>Play the video in full screen mode for a better viewing experience.<\/p>\n<p>Function is here:<\/p>\n<pre><code>\r\nfunction f=makeEraseDisplayFunction\r\n\r\n% Length of last string\r\nlen=0;\r\n\r\n% Return handle to function\r\nf = @displayFunction;\r\n\r\n% Nested Function\r\n    function displayFunction(str,varargin)\r\n        \r\n        if nargin>=2\r\n            eraseThisTime=varargin{1}; % True or false\r\n            if ~eraseThisTime\r\n                len = 0;\r\n            end\r\n        end\r\n        \r\n        % Erase previous characters\r\n        eraseStr=repmat('\\b',[1 len] );\r\n        fprintf(eraseStr);\r\n        \r\n        % Display New characters\r\n        fprintf(str);\r\n        \r\n        % Decide what to do at next call\r\n        if nargin == 3\r\n            eraseNextTime=varargin{2}; % True or false\r\n            \r\n            if eraseNextTime\r\n                len = length(str);\r\n            end\r\n            len = 0;\r\n        else\r\n            len = length(str);\r\n        end\r\n    end\r\nend\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<div class=\"thumbnail thumbnail_asset asset_overlay video\"><a href=\"https:\/\/blogs.mathworks.com\/videos\/2016\/08\/17\/displaying-progress-status-of-long-running-script-part-4-display-erase-utility\/?dir=autoplay\"><img decoding=\"async\" src=\"https:\/\/cf-images.us-east-1.prod.boltdns.net\/v1\/static\/62009828001\/a0c5d2c6-0ddb-4e0a-a544-b1181c8d7289\/7a5f02b7-6414-4e94-8d81-c8678751dad2\/640x360\/match\/image.jpg\" onError=\"this.style.display ='none';\"\/><\/p>\n<div class=\"overlay_container\">\n      <span class=\"icon-video icon_color_null\"><time class=\"video_length\">47:21<\/time><\/span>\n      <\/div>\n<p>      <\/a><\/div>\n<p>Sometimes when displaying the progress of a long running script, there is so much output at the command window that there is too much to scroll through or the buffer fills up and you can&#8217;t go&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/videos\/2016\/08\/17\/displaying-progress-status-of-long-running-script-part-4-display-erase-utility\/\">read more >><\/a><\/p>\n","protected":false},"author":133,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[27,4],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/2595"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/users\/133"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/comments?post=2595"}],"version-history":[{"count":10,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/2595\/revisions"}],"predecessor-version":[{"id":3047,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/2595\/revisions\/3047"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/media?parent=2595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/categories?post=2595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/tags?post=2595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}