matlab Command--Directory operation (Windows&linux)
1. Filesep
Used to return the directory delimiter for the current platform, Windows is a backslash (\), and Linux is a slash (/). Sometimes this command is used in conjunction with the ISPC command, which allows you to set up directory separators flexibly.
2. FullFile
Used to concatenate several strings into a full path, automatically populating the directory separator with different operating systems. For example:
>> f=fullfile (' D: ', ' Matlab ', ' example.txt ')
F=d:\matlab\example.txt
(In Windows, "D:\" represents the D drive, "D:" means directory)
3. Fileparts
Used to split a full file name into 4 parts: path, file name, extension, version number. For example: >> f=fullfile (' D: ', ' Matlab ', ' example.txt ');
>>[pathstr,name,ext,versn]=fileparts (f)
Pathstr=d:\matlab
Name=example
Ext=.txt
Versn= "
4. Pathsep
Returns the path delimiter for the current platform. Windows is a semicolon (;), Linux is a colon (:).
5. Exist
Can be used to determine whether a directory or file exists, and different return values have different meanings. For example:
>> f=fullfile (' D: ', ' Matlab ', ' example.txt ');
>>exist (f)
ans=2
>>exist (' D:\Matlab ')
Ans =7
6. Which
You can get its full path through a function or script name, as well as handle overloaded functions, such as:
>> which abs (0)
C:\MATLAB7\toolbox\matlab\elfun\ @double \abs.bi% double method
>> which abs (single (0))
C:\MATLAB7\toolbox\matlab\elfun\ @single \abs.bi% single method
7. Isdir
>> p= ' D:\Matlab ';
>> f=fullfile (P, ' example.txt ');
>> Isp=isdir (p)
isp=1
>> Isf=isdir (f)
isf=0
8. Dir
>> p= ' D:\Matlab ';
>>files=dir (p)
files =
8x1 struct array with fields:
name
date
bytes
isdir
9. cd
Used to toggle the current working directory. For example:
>>CD (' c:/toolbox/matlab/demos ')% switch current working directory to Demos
>>CD. % switch current working directory to MATLAB
Ten. pwd
The path used for the current working directory is consistent with the PWD command under Linux. For example:
>> pwd
Ans =c:\matlab7\work
one-path
<<path % Queries all current search paths (Matlabpath)
<<p=path % The current search path exists in the string variable p
<<path (' NewPath ') % Set the current search path to NewPath
<<path ( Path, ' NewPath ') % Add a new directory to the path NewPath
<<path (' NewPath ', path) % Pre-add a new directory to the current search path Nespath
Addpath and rmpath .
Used to add and remove the MATLAB search path. For example:
<<addpath (' directory ')% joins full path directory to the top of the current search path
<<rmpath
What
Used to show which MATLAB files exist in a directory, and if you enter the full path, you can list the files in the specified directory. For example:
<<what
<<what dirname
<<what (' dirname ')
Where DirName is the name of the path to find, the path in the MATLAB search path, there is no need to enter the full name, only enter the last or last level two is enough.
PATH2RC.
Saves the current MATLAB search path to the pathdef.m file.
MATLAB command--Directory operation (Windows&linux)