To run this file you can either change the MATLAB current folder
—Oops, on re-reading your question, my answer isn’t very helpful. I’ll leave it below since it is somewhat relevant. Show
I usually add to path unless the data for the specified script is in the same folder. If the script doesn’t rely on data, or you will be manually entering data or selecting it from somewhere else, this is usually the safest option.
Main Content SyntaxDescriptionexample
example
example
Examplescollapse all Change Current Folder Using Full and Relative Paths
Change the current folder to the featured examples folder for MATLAB R2017a, assuming that version is installed on your cd 'C:\Program Files\MATLAB\R2017a\examples\matlab_featured'
Using the full path, change the current folder from Use a relative path to change the current folder from cd examples\matlab_featured
Change, and then Restore Current FolderChange the current folder to the featured examples folder for MATLAB R2017a, assuming that version is installed on your Change the current folder to the featured examples folder for MATLAB R2017a. cd 'C:\Program Files\MATLAB\R2017a\examples\matlab_featured'
Change the current folder to oldFolder = cd('C:\Program Files')
oldFolder = 'C:\Program Files\MATLAB\R2017a\examples\matlab_featured' Use the Change the current folder back to the original folder, using the stored path. Use the C:\Program Files\MATLAB\R2017a\examples\matlab_featured Change Current Folder to User Home Folder on UNIX®Change the current folder to the featured examples folder for MATLAB R2016b, assuming that version is installed in your user home folder on a UNIX platform. cd ~/MATLAB/R2016b/examples/matlab_featured
Input Argumentscollapse all newFolder — New folder path character vector | string scalarNew folder path to which you want to change the current folder, specified as a character vector or string scalar. If Valid values include a full or relative path or one of these values.
If On UNIX® systems, you can use the ~ (tilde) character to represent the user home folder. For example, MATLAB resolves folder path names containing ' Output Argumentscollapse all oldFolder — Previous current folder character vectorPrevious current folder that was in place before you issued the More Aboutcollapse all Current FolderThe current folder is a reference location that MATLAB uses to find files. This folder is sometimes referred to as the current directory, current working folder, or present working directory. Extended CapabilitiesThread-Based Environment Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.Usage notes and limitations:
For more information, see Run MATLAB Functions in Thread-Based Environment. Version HistoryIntroduced before R2006a expand all R2022a: Leading whitespace characters in drive letter paths on Windows cause errorOn Windows machines, leading whitespace characters in the input path are no longer trimmed. Input paths containing leading whitespace characters cause an error to be thrown instead.
How can you change the path of the current directory folder in MATLAB?Folder changes are global. Therefore, if you use cd within a function, the folder change persists after MATLAB® finishes executing the function. oldFolder = cd( newFolder ) returns the existing current folder to oldFolder , and then it changes the current folder to newFolder .
What is the current folder in MATLAB?The Current Folder browser enables you to interactively manage files and folders in MATLAB®. Use the Current Folder browser to view, create, open, move, and rename files and folders in the current folder.
|