To change Current Folder to the folder of .m File
392 views (last 30 days)
Image Analyst on 17 Apr 2013
Edited: Image Analyst on 17 Apr 2013
Here's some code I got from Brett Shoelson of the Mathworks:
% Change the current folder to the folder of this m-file.
Edit: Note that the isdeployed is important if you will be compiling and deploying your application. This let's it operate both for you, as the developer, and for your deployed application where it will skip the cd because doing cd like that in a deployed app can wreak havoc. If you won't be doing compiling, then you can do just the cd without the if.
Florian on 13 Jul 2018
mfile_name = mfilename('fullpath');
[pathstr,name,ext] = fileparts(mfile_name);