{"id":4738,"date":"2013-08-02T09:00:23","date_gmt":"2013-08-02T13:00:23","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=4738"},"modified":"2017-05-23T14:44:18","modified_gmt":"2017-05-23T18:44:18","slug":"start-matlab-in-last-working-directory","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2013\/08\/02\/start-matlab-in-last-working-directory\/","title":{"rendered":"Start MATLAB in Last Working Directory"},"content":{"rendered":"\r\n<div class=\"content\"><!--introduction--><!--\/introduction--><p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911\">Brett<\/a>'s Pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/5793-startup-matlab-in-last-working-folder\">\"Startup MATLAB in Last Working Directory\"<\/a>, by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/3777\">Michelle Hirsch<\/a>.<\/p><p>Several years ago, <a href=\"https:\/\/blogs.mathworks.com\/loren\/\">Loren<\/a> wrote a <a href=\"https:\/\/blogs.mathworks.com\/loren\/2009\/03\/03\/whats-in-your-startupm\/\">blog post<\/a> encouraging people to share the contents (at least thematically) of their startup files. A lengthy and interesting discussion ensued--it's still worth a read. More recently (last week, in fact!), Sean guest-selected as a <a href=\"https:\/\/blogs.mathworks.com\/pick\/2013\/07\/26\/save-and-load-matlab-projects-in-the-editor\/\">Pick-of-the-Week<\/a> <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/29275\">Kevin Bartlett<\/a>'s <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/41505-matproj-varargin-\">very useful submission<\/a> that facilitates the saving of \"projects\"; I wanted to follow Sean's post with a lighter-weight approach to resuming one's previous coding activities in MATLAB.<\/p><p>When I close MATLAB in the middle of working on a project (or projects), I typically leave relevant editor documents open--whenever it's not inconvenient to do so. That way I can right-click on the tab for an open document and change, relatively painlessly, to its parent directory:<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/SaveMLLWD.gif\" alt=\"\"> <\/p><p>I haven't (yet) implemented Kevin's \"projects\" approach, but tonight, I changed my long-static <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/startup.html\">startup.m<\/a> file to incorporate Michelle's \"Last Working Directory (LWD)\" instructions. Michelle's file contains a small HTML document with instructions--and code snippets--detailing how to modify your startup and <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/finish.html\">finish<\/a> files to <i>automatically<\/i> resume working in the directory in which you were last working . It's trivially easy to implement, once you know how, and it saves me the \"trouble\" of having to manually click to resume my last session.<\/p><p>Also, I'm embarassed to say that, though I've used MATLAB (and 'startup') for nearly 20 years, I never even realized we <i>have<\/i> a 'finish' file to accompany startup.<\/p><p>As always, I welcome your <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=4738#respond\">thoughts and comments<\/a>. Or leave feedback for Michelle <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/5793-startup-matlab-in-last-working-folder#comments\">here<\/a>.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_cc3c3868bcec433d9ae130590a4bd6c3() {\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='cc3c3868bcec433d9ae130590a4bd6c3 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' cc3c3868bcec433d9ae130590a4bd6c3';\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        copyright = 'Copyright 2013 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 copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\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     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_cc3c3868bcec433d9ae130590a4bd6c3()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2013a<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2013a<br><\/p><\/div><!--\r\ncc3c3868bcec433d9ae130590a4bd6c3 ##### SOURCE BEGIN #####\r\n%% Start MATLAB in Last Working Directory\r\n\r\n%% \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911 Brett>'s Pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/5793-startup-matlab-in-last-working-folder \"Startup MATLAB in Last Working Directory\">, by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/3777 Michelle Hirsch>.\r\n\r\n%%\r\n% Several years ago, <https:\/\/blogs.mathworks.com\/loren\/ Loren> wrote a\r\n% <https:\/\/blogs.mathworks.com\/loren\/2009\/03\/03\/whats-in-your-startupm\/ blog post>\r\n% encouraging people to share the contents (at least thematically) of their\r\n% startup files. A lengthy and interesting discussion ensuedREPLACE_WITH_DASH_DASHit's still\r\n% worth a read. More recently (last week, in fact!), Sean guest-selected as\r\n% a <https:\/\/blogs.mathworks.com\/pick\/2013\/07\/26\/save-and-load-matlab-projects-in-the-editor\/ Pick-of-the-Week>\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/29275 Kevin Bartlett>'s\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/41505-matproj-varargin- very useful submission>\r\n% that facilitates the saving of \"projects\"; I\r\n% wanted to follow Sean's post with a lighter-weight approach to resuming\r\n% one's previous coding activities in MATLAB. \r\n\r\n%%\r\n% When I close MATLAB in the middle of working on a project (or projects),\r\n% I typically leave relevant editor documents openREPLACE_WITH_DASH_DASHwhenever it's not\r\n% inconvenient to do so. That way I can right-click on the tab for an open\r\n% document and change, relatively painlessly, to its parent directory:\r\n\r\n%%\r\n% \r\n% <<https:\/\/blogs.mathworks.com\/pick\/files\/SaveMLLWD.gif>>\r\n% \r\n\r\n%%\r\n% I haven't (yet) implemented Kevin's \"projects\" approach, but tonight, I\r\n% changed my long-static\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/startup.html?searchHighlight=startup startup.m> \r\n% file to incorporate Michelle's \"Last Working Directory (LWD)\"\r\n% instructions. Michelle's file contains a small HTML document with\r\n% instructionsREPLACE_WITH_DASH_DASHand code snippetsREPLACE_WITH_DASH_DASHdetailing how to modify your startup and \r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/finish.html finish> files to\r\n% _automatically_ resume working in the directory in which you were last \r\n% working . It's trivially easy to implement, once you know how, and it saves me the\r\n% \"trouble\" of having to manually click to resume my last session.\r\n\r\n%%\r\n% Also, I'm embarassed to say that, though I've used MATLAB (and 'startup') for nearly 20\r\n% years, I never even realized we _have_ a 'finish' file to accompany\r\n% startup. \r\n\r\n%%\r\n% As always, I welcome your\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=4738#respond thoughts and comments>.\r\n% Or leave feedback for Michelle <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/5793-startup-matlab-in-last-working-folder#comments here>.\r\n##### SOURCE END ##### cc3c3868bcec433d9ae130590a4bd6c3\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/SaveMLLWD.gif\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\nBrett's Pick this week is \"Startup MATLAB in Last Working Directory\", by Michelle Hirsch.Several years ago, Loren wrote a blog post encouraging people to share the contents (at least thematically)... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2013\/08\/02\/start-matlab-in-last-working-directory\/\">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\/4738"}],"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=4738"}],"version-history":[{"count":10,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4738\/revisions"}],"predecessor-version":[{"id":8622,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4738\/revisions\/8622"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=4738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=4738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=4738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}