| Contents | Index |
cd(newFolder)
oldFolder = cd(newFolder)
cd
cd(newFolder) changes the current folder to newFolder.
oldFolder = cd(newFolder) returns the existing current folder as a string to oldFolder, and then changes the current folder to newFolder.
cd displays the current folder.
When using the command syntax (cd newfolder), if the newFolder string contains spaces, enclose the string in single quotation marks.
On UNIX platforms, use the ~ (tilde) character to represent the user home directory.
If you use cd within a subfunction, the folder change persists after program control returns from the function. That is, the scope of the folder change is global, rather than local to the subfunction in which you change it.
oldFolder |
A string specifying the current folder that was in place when you issued the cd command. |
The current folder is a reference location that MATLAB uses to find files. See The Current Folder.
Use cd with the matlabroot function to change the current folder to the examples directory for the currently running version of MATLAB:
cd(fullfile(matlabroot, '/help/techdoc/matlab_env/examples'))
On a Microsoft Windows platform, specify the full path to change the current folder from any location to the examples directory for MATLAB Version 7.11 (R2010b), assuming that version is installed on your C: drive:
cd('C:/Program Files/MATLAB/R2010b/help/techdoc/matlab_env/examples')
% Change the current folder from
% C:/Program Files/MATLAB/R2010b/help/techdoc/matlab_env/examples to
% C:/Program Files/MATLAB/R2010b/help/techdoc:
cd ../..
% Use a relative path to change the current folder from
% C:/Program Files/MATLAB/R2010b/help/techdoc back to
% C:/Program Files/MATLAB/R2010b/help/techdoc/matlab_env/examples:
cd matlab_env/examples
% Change the current folder from its current location to a new location,
% but save its previous location. Later, change the current folder to the
% previous location.
% This returns C:/Program Files/MATLAB/R2010b/help/techdoc/matlab_env/examples
% to oldFolder, and then changes the current folder to C:/Program Files:
oldFolder = cd('C:/Program Files')
% Display current folder:
pwd
% Change the current folder to the previous location:
cd(oldFolder)
pwdOn a UNIX platform, change the current folder to the examples directory for the currently running version of MATLAB, assuming it is installed in your home location:
cd('~/help/techdoc/matlab_env/examples')As an alternative to the cd function:
Use the Current Folder field in the MATLAB desktop toolbar.
Use the address bar in the Current Folder browser.
You can open the Current Folder browser by issuing the filebrowser command.
dir | fileparts | path | pwd | what
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |