有关文件路径的几个函数在编程中的作用
Last Edit 2014/1/16
1,genpath: (gen=generate,顾名思义就是一个产生路径的函数,这个路径须存在)
genpathgenpath directoryp = genpath('directory')
>>genpath
其结果为 C:\Program Files\MATLAB\R2009a\toolbox;C:\Program Files\MATLAB\R2009a\toolbox\aero;….
(本人机器上的MATLAB2009a)
>>path=genpath(‘D:\Code\’)% 本人D盘的一个文件夹,如图
结果:显示这个路径下所有的文件夹
D:\Ccode;D:\Ccode\OpenCV_test;D:\Ccode\OpenCV_test\Debug;D:\Ccode\OpenCV_test\OpenCV_test;D:\Ccode\OpenCV_test\OpenCV_test\Debug;D:\Ccode\OpenCV_test\images;D:\Ccode\Opencv_Event;D:\Ccode\Opencv_Event\Debug;D:\Ccode\Opencv_Event\Opencv_Event;D:\Ccode\Opencv_Event\Opencv_Event\Debug;D:\Ccode\STL;D:\Ccode\STL\Debug;D:\Ccode\STL\STL;D:\Ccode\STL\STL\Debug;
2,addpath(),添加一条路径,一般会和genpath联合使用
>>addpath( genpath(‘D:\Code\’) )
3,fullfile() 构造一条路径
path=fullfile(dir1,dir2,…,filename);
f = fullfile('C:', 'Applications', 'matlab', 'myfun.m')f =C:\Applications\matlab\myfun.m
4,fileparts,将一条路径分成几个部分,如下例子所示
file = '\home\user4\matlab\classpath.txt';[pathstr, name, ext, versn] = fileparts(file)pathstr = \home\user4\matlabname = classpathext = .txtversn = ''
从参考文档上搞来的,方便自己学习~~~~
本文转载自:CSDN博客
欢迎加入我爱机器学习QQ14群:336582044
微信扫一扫,关注我爱机器学习公众号