{"id":2435,"date":"2009-06-19T11:58:16","date_gmt":"2009-06-19T11:58:16","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2009\/06\/19\/close-all-but\/"},"modified":"2009-06-19T11:58:16","modified_gmt":"2009-06-19T11:58:16","slug":"close-all-but","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2009\/06\/19\/close-all-but\/","title":{"rendered":"Close All But&#8230;"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p>Like this blog post, today's Pick is short and sweet. File <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/24420-close-all-figures-except-those-listed\">cab.m<\/a>, by new first-time contributor <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/24420-close-all-figures-except-those-listed\">Karl<\/a>, <i>allows you to keep only the figures you specify, and to close the rest<\/i> .\r\n      <\/p>\r\n   <\/introduction>\r\n   <p>Back in 2004, our predecessor <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/4987\">Doug Hull<\/a> selected file <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/181-keep\">keep<\/a> as a <a href=\"https:\/\/blogs.mathworks.com\/pick\/2004\/02\/04\/clear-all-but-specified-variables\/\">Pick of the Week<\/a>. In that write-up, Doug wrote: \"I find KEEP to be one of those functions I use so much that I forget it isn't part of MATLAB.\"\r\n      I couldn't agree more, and today's Pick is a great companion; it's the \"figure version of keep.\"\r\n   <\/p>\r\n   <p>So now I can use my own <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=togglefig\">togglefig<\/a> function to create my figures, and CAB to destroy them.\r\n   <\/p>\r\n   <p>Comments? Share them <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2435#respond\">here<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_546c8f187aee4f299912d0846de63393() {\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='546c8f187aee4f299912d0846de63393 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 546c8f187aee4f299912d0846de63393';\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 = 'Brett Shoelson';\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_546c8f187aee4f299912d0846de63393()\"><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.8<br><\/p>\r\n<\/div>\r\n<!--\r\n546c8f187aee4f299912d0846de63393 ##### SOURCE BEGIN #####\r\n%% Close All But...\r\n% Like this blog post, today's Pick is short and sweet. File\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/24420-close-all-figures-except-those-listed cab.m>,\r\n% by new first-time contributor\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/24420-close-all-figures-except-those-listed Karl>,  \r\n% _allows you to keep only the figures you specify, and to close\r\n% the rest_ .\r\n\r\n%% \r\n% Back in 2004, our predecessor <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/4987 Doug Hull> selected file <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/181-keep keep>\r\n% as a <https:\/\/blogs.mathworks.com\/pick\/2004\/02\/04\/clear-all-but-specified-variables\/ Pick of the Week>.\r\n% In that write-up, Doug wrote: \"I find KEEP to be one of those\r\n% functions I use so much that I forget it isn't part of MATLAB.\"\r\n% I couldn't agree more, and today's Pick is a great companion;\r\n% it's the \"figure version of keep.\" \r\n\r\n%%\r\n% So now I can use my own\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=togglefig togglefig> function \r\n% to create my figures, and CAB to destroy them. \r\n\r\n%%\r\n% Comments? Share them\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2435#respond here>.\r\n##### SOURCE END ##### 546c8f187aee4f299912d0846de63393\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Like this blog post, today's Pick is short and sweet. File cab.m, by new first-time contributor Karl, allows you to keep only the figures you specify, and to close the rest .\r\n      \r\n  ... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2009\/06\/19\/close-all-but\/\">read more >><\/a><\/p>","protected":false},"author":34,"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\/2435"}],"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\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2435"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2435\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}