MATLAB基本操作(七):有关文件路径的几个函数在编程中的作用

来源:互联网 发布:淘宝手机话费充值 编辑:程序博客网 时间:2024/05/22 06:11
1,genpath: (gen=generate,顾名思义就是一个产生路径的函数,这个路径须存在)
[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
  1. genpath  
  2. genpath directory  
  3. p = genpath('directory')  

>>genpath
其结果为 C:\Program Files\MATLAB\R2009a\toolbox;C:\Program Files\MATLAB\R2009a\toolbox\aero;....
                (本人机器上的MATLAB2009a)
>>path=genpath('D:\Code\')% 本人D盘的一个文件夹,如图
结果:显示这个路径下所有的文件夹
[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
  1. D:\Ccode;  
  2. D:\Ccode\OpenCV_test;  
  3. D:\Ccode\OpenCV_test\Debug;  
  4. D:\Ccode\OpenCV_test\OpenCV_test;  
  5. D:\Ccode\OpenCV_test\OpenCV_test\Debug;  
  6. D:\Ccode\OpenCV_test\images;D:\Ccode\Opencv_Event;  
  7. D:\Ccode\Opencv_Event\Debug;D:\Ccode\Opencv_Event\Opencv_Event;  
  8. D:\Ccode\Opencv_Event\Opencv_Event\Debug;  
  9. D:\Ccode\STL;  
  10. D:\Ccode\STL\Debug;  
  11. D:\Ccode\STL\STL;  
  12. D:\Ccode\STL\STL\Debug;  


2,addpath(),添加一条路径,一般会和genpath联合使用
>>addpath(genpath('D:\Code\'))

3,fullfile() 构造一条路径
path=fullfile(dir1,dir2,...,filename);
[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
  1. f = fullfile('C:''Applications''matlab''myfun.m')  
  2. f =  
  3. C:\Applications\matlab\myfun.m  

4,fileparts,将一条路径分成几个部分,如下例子所示
[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
  1. file = '\home\user4\matlab\classpath.txt';  
  2. [pathstr, name, ext, versn] = fileparts(file)  
  3.   
  4. pathstr =  
  5.    \home\user4\matlab  
  6. name =  
  7.    classpath  
  8. ext =  
  9.    .txt  
  10. versn =  
  11.      '' 
0 0
原创粉丝点击