Matlab path operation

Source: Internet
Author: User

1, Filesep

Returns the directory separator for the current platform, Windows is backslash (\), Linux is slash (/)

2, Pathsep
Returns the path delimiter for the current platform. Windows is a semicolon (;), Linux is a colon (:)

3, FullFile
Concatenate a number of strings into a full path. For example:
>> f=fullfile (' D: ', ' Matlab ', ' example.txt ')
F=d:\matlab\example.txt
4, 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= "
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
Determine if a path represents a directory, for example:
>> p= ' D:\Matlab ';
>> f=fullfile (P, ' example.txt ');
>> Isp=isdir (P)
Isp=1
>> Isf=isdir (f)
Isf=0
8. Dir
Lists the contents of a directory, the return value is a struct array type, contains the following parts: Name: File or directory names, date: modified date; bytes: file size; Isdir: Whether it is a directory. For example:
>> p= ' D:\Matlab ';
>>files=dir (P)
Files =
8x1 struct array with fields:
Name
Date
bytes
Isdir
9. cd
Toggles the current working directory. For example:
>>CD (' c:/toolbox/matlab/demos ')% switch current working directory to Demos
>>CD. % switch the current working directory to the previous level directory
10. pwd
The path to the current working directory. For example:
>> pwd

Ans =c:\matlab7\work


The following are not commonly used

11. Path
The operation on the search path. For example:
<<path% query All current search paths (Matlabpath)
<<p=path% The current search path exists in the string variable p
<<path (' NewPath ')% sets the current search path to NewPath
<<path (Path, ' NewPath ')% adds a new directory to the path NewPath
<<path (' NewPath ', path)% pre-adds a new directory to the current search path Nespath
12, 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
13. 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.
14, PATH2RC
Saves the current MATLAB search path to the pathdef.m file.

Matlab path operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.