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

有关文件路径的几个函数在编程中的作用
Last Edit 2014/1/16
1,genpath: (gen=generate,顾名思义就是一个产生路径的函数,这个路径须存在)
genpath
genpath directory
p = 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\matlab
name =
   classpath
ext =
   .txt
versn =
     ''

从参考文档上搞来的,方便自己学习~~~~


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值