{"id":2501,"date":"2009-12-04T14:24:54","date_gmt":"2009-12-04T14:24:54","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2009\/12\/04\/back-to-work-with-a-push-and-a-pop\/"},"modified":"2009-12-04T14:24:54","modified_gmt":"2009-12-04T14:24:54","slug":"back-to-work-with-a-push-and-a-pop","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2009\/12\/04\/back-to-work-with-a-push-and-a-pop\/","title":{"rendered":"Back to Work with a Push and a Pop"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\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\/8103-pushd\"><tt>pushd &amp; popd<\/tt><\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/12095\">Peter Bodin<\/a>.\r\n      <\/p>\r\n      <p>Navigating through folders is a big part of my MATLAB workflow, especially because I may be working on multiple demos\/projects\r\n         at any one time. When I change folders, invariably I may want to come back to where I was.\r\n      <\/p>\r\n   <\/introduction>\r\n   <h3>Contents<\/h3>\r\n   <div>\r\n      <ul>\r\n         <li><a href=\"#1\">Example<\/a><\/li>\r\n         <li><a href=\"#8\">In Addition...<\/a><\/li>\r\n         <li><a href=\"#9\">Interactive Alternative<\/a><\/li>\r\n         <li><a href=\"#10\">Comments<\/a><\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <h3>Example<a name=\"1\"><\/a><\/h3>\r\n   <p>Here's an example illustrating my workflow. I'll use <tt>pushd<\/tt> and <tt>popd<\/tt> to help me do this.\r\n   <\/p>\r\n   <p>I'm currently working on this blog post. I am located here:<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">pwd<\/pre><pre style=\"font-style:oblique\">ans =\r\nC:\\MyStuff\\Work\\NoCopy\\Blog\\POTW\\PushPop\r\n<\/pre><p>I just got a call from Bob and Brett saying that they need an updated version of the GUI Building demo ASAP. Time to switch\r\n      folders!\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\"><span style=\"color: #228B22\">% works like CD<\/span>\r\npushd <span style=\"color: #A020F0\">C:\\MyStuff\\Work\\Demos2009b\\GUIBuilding<\/span>\r\npwd<\/pre><pre style=\"font-style:oblique\">ans =\r\nC:\\MyStuff\\Work\\Demos2009b\\GUIBuilding\r\n<\/pre><p>I realize that I am missing a couple of key files for this demo. Well, that's understandable. I haven't ported over the files\r\n      from my master version. I'm not quite sure which files I need, so let me go check.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">pushd <span style=\"color: #A020F0\">..\\..\\Demos_public\\GUIBuilding<\/span>\r\npwd<\/pre><pre style=\"font-style:oblique\">ans =\r\nC:\\MyStuff\\Work\\Demos_public\\GUIBuilding\r\n<\/pre><p>I find out that I need two files: \"myFilter.m\" and \"myPSD.m\". Let me capture this folder name.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">copyFromFolder = pwd;<\/pre><p>I go back to my R2009b demos folder and <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/copyfile.html\">copy<\/a> over the two files.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">popd\r\npwd\r\ncopyfile(fullfile(copyFromFolder, <span style=\"color: #A020F0\">'myFilter.m'<\/span>));\r\ncopyfile(fullfile(copyFromFolder, <span style=\"color: #A020F0\">'myPSD.m'<\/span>));<\/pre><pre style=\"font-style:oblique\">ans =\r\nC:\\MyStuff\\Work\\Demos2009b\\GUIBuilding\r\n<\/pre><p>Now, I can <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/zip.html\">zip<\/a> this up and <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/sendmail.html\">email<\/a> it to Bob and Brett.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">zip(<span style=\"color: #A020F0\">'GUIDemo.zip'<\/span>, <span style=\"color: #0000FF\">...<\/span>\r\n  {<span style=\"color: #A020F0\">'filteringGUI.fig'<\/span>, <span style=\"color: #A020F0\">'filteringGUI.m'<\/span>, <span style=\"color: #0000FF\">...<\/span>\r\n  <span style=\"color: #A020F0\">'myFilter.m'<\/span>, <span style=\"color: #A020F0\">'myPSD.m'<\/span>, <span style=\"color: #A020F0\">'myImportfile.m'<\/span>});\r\n\r\n<span style=\"color: #228B22\">% I'm commenting this part out so that it won't keep sending email to my<\/span>\r\n<span style=\"color: #228B22\">% buddies every time I publish this script.<\/span>\r\n<span style=\"color: #228B22\">%<\/span>\r\n<span style=\"color: #228B22\">%   sendmail({'Robert.Bemis@mathworks.com', 'Brett.Shoelson@mathworks.com'}, ...<\/span>\r\n<span style=\"color: #228B22\">%     'GUI Building Demo', 'Hi Bob and Brett, here it is!', 'GUIDemo.zip');<\/span><\/pre><p>Now, I'm ready to get back to my blog post! Ta-dah!<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">popd\r\npwd<\/pre><pre style=\"font-style:oblique\">ans =\r\nC:\\MyStuff\\Work\\NoCopy\\Blog\\POTW\\PushPop\r\n<\/pre><h3>In Addition...<a name=\"8\"><\/a><\/h3>\r\n   <p>Another nice feature of <tt>pushd<\/tt> is that you can pass in any file that is on the MATLAB path, and it will go to that directory. For example, I know that there\r\n      is an AVI called \"rhinos.avi\", which is one of the demo files from the <a href=\"https:\/\/www.mathworks.com\/products\/image\/\">Image Processing Toolbox.<\/a> I want to see the other demo files from that toolbox.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">pushd <span style=\"color: #A020F0\">rhinos.avi<\/span>\r\npwd\r\n\r\n<span style=\"color: #228B22\">% go back<\/span>\r\npopd<\/pre><pre style=\"font-style:oblique\">ans =\r\nC:\\Program Files\\MATLAB\\R2009b\\toolbox\\images\\imdemos\r\n<\/pre><h3>Interactive Alternative<a name=\"9\"><\/a><\/h3>\r\n   <p>If you'd rather click your way through, we have that built-in to the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/matlab_env\/br5rtt_.html\">Current Folder Browser<\/a>.\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/pushdpopd_cfb.png\"> <\/p>\r\n   <p>Notice the Back and Forward buttons to \"pop\" back to where you were. Ken and Mike blogged about it <a href=\"https:\/\/blogs.mathworks.com\/community\/2008\/11\/03\/meet-the-new-current-directory-navigation-bar\/\">here<\/a>.\r\n   <\/p>\r\n   <h3>Comments<a name=\"10\"><\/a><\/h3>\r\n   <p>These types of tools help users in the development phase. They may never show up in the end product, but since MATLAB is a\r\n      development platform, these functions could drastically improve the MATLAB experience. <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2501#respond\">Let me know<\/a> of other File Exchange entries that fall into this category. I can already think of a couple.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_b2fd7053b0e8411c9c251d0c0daf19d0() {\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='b2fd7053b0e8411c9c251d0c0daf19d0 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' b2fd7053b0e8411c9c251d0c0daf19d0';\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_b2fd7053b0e8411c9c251d0c0daf19d0()\"><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\nb2fd7053b0e8411c9c251d0c0daf19d0 ##### 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\/8103-pushd\r\n% |pushd & popd|> by \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/12095\r\n% Peter Bodin>.\r\n%\r\n% Navigating through folders is a big part of my MATLAB workflow,\r\n% especially because I may be working on multiple demos\/projects at any one\r\n% time. When I change folders, invariably I may want to come back to where\r\n% I was.\r\n\r\n\r\n%% Example\r\n% Here's an example illustrating my workflow. I'll use |pushd| and |popd|\r\n% to help me do this.\r\n%\r\n% I'm currently working on this blog post. I am located here:\r\n\r\npwd\r\n\r\n%%\r\n% I just got a call from Bob and Brett saying that they need an updated\r\n% version of the GUI Building demo ASAP. Time to switch folders!\r\n\r\n% works like CD\r\npushd C:\\MyStuff\\Work\\Demos2009b\\GUIBuilding\r\npwd\r\n\r\n%%\r\n% I realize that I am missing a couple of key files for this demo. Well,\r\n% that's understandable. I haven't ported over the files from my master\r\n% version. I'm not quite sure which files I need, so let me go check.\r\n\r\npushd ..\\..\\Demos_public\\GUIBuilding\r\npwd\r\n\r\n%%\r\n% I find out that I need two files: \"myFilter.m\" and \"myPSD.m\". Let me\r\n% capture this folder name.\r\n\r\ncopyFromFolder = pwd;\r\n\r\n%%\r\n% I go back to my R2009b demos folder and\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/copyfile.html\r\n% copy> over the two files.\r\n\r\npopd\r\npwd\r\ncopyfile(fullfile(copyFromFolder, 'myFilter.m'));\r\ncopyfile(fullfile(copyFromFolder, 'myPSD.m'));\r\n\r\n%%\r\n% Now, I can\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/zip.html zip>\r\n% this up and\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/sendmail.html\r\n% email> it to Bob and Brett.\r\n\r\nzip('GUIDemo.zip', ...\r\n  {'filteringGUI.fig', 'filteringGUI.m', ...\r\n  'myFilter.m', 'myPSD.m', 'myImportfile.m'});\r\n\r\n% I'm commenting this part out so that it won't keep sending email to my\r\n% buddies every time I publish this script.\r\n%\r\n%   sendmail({'Robert.Bemis@mathworks.com', 'Brett.Shoelson@mathworks.com'}, ...\r\n%     'GUI Building Demo', 'Hi Bob and Brett, here it is!', 'GUIDemo.zip');\r\n\r\n%%\r\n% Now, I'm ready to get back to my blog post! Ta-dah!\r\n\r\npopd\r\npwd\r\n\r\n%% In Addition...\r\n% Another nice feature of |pushd| is that you can pass in any file that is\r\n% on the MATLAB path, and it will go to that directory. For example, I know\r\n% that there is an AVI called \"rhinos.avi\", which is one of the demo files\r\n% from the <https:\/\/www.mathworks.com\/products\/image\/ Image Processing\r\n% Toolbox.> I want to see the other demo files from that toolbox.\r\n\r\npushd rhinos.avi\r\npwd\r\n\r\n% go back\r\npopd\r\n\r\n%% Interactive Alternative\r\n% If you'd rather click your way through, we have that built-in to the\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/matlab_env\/br5rtt_.html\r\n% Current Folder Browser>.\r\n%\r\n% <<pushdpopd_cfb.png>>\r\n%\r\n% Notice the Back and Forward buttons to \"pop\" back to where you were. Ken\r\n% and Mike blogged about it \r\n% <https:\/\/blogs.mathworks.com\/community\/2008\/11\/03\/meet-the-new-current-directory-navigation-bar\/\r\n% here>.\r\n\r\n%% Comments\r\n% These types of tools help users in the development phase. They may\r\n% never show up in the end product, but since MATLAB is a development\r\n% platform, these functions could drastically improve the MATLAB\r\n% experience. <https:\/\/blogs.mathworks.com\/pick\/?p=2501#respond Let me know>\r\n% of other File Exchange entries that fall into\r\n% this category. I can already think of a couple.\r\n##### SOURCE END ##### b2fd7053b0e8411c9c251d0c0daf19d0\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Jiro's pick this week is pushd &amp; popd by Peter Bodin.\r\n      \r\n      Navigating through folders is a big part of my MATLAB workflow, especially because I may be working on... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2009\/12\/04\/back-to-work-with-a-push-and-a-pop\/\">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\/2501"}],"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=2501"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2501\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}