加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

matlab代码中获取当前m文件所在的路径 转的

(2014-02-26 15:29:41)
标签:

matlab

it

分类: Matlab

文件放在哪里,直接可以运行。不用change folder,会把M文件位置变成当前工作目录。http://www/uc/myshow/blog/misc/gif/E___6708EN00SIGG.gif转的" TITLE="matlab代码中获取当前m文件所在的路径 转的" />

%save m-file as aa.m 

function res=aa()

clc

p1 = mfilename('fullpath')

i=findstr(p1,'\')

p1=p1(1:i(end))

cd(p1)

 end

 

 

 

 http://www/uc/myshow/blog/misc/gif/E___7474ZH00SIGG.gif转的" TITLE="matlab代码中获取当前m文件所在的路径 转的" />
mfilename


File name of currently running function
Syntax

 

mfilename
p = mfilename('fullpath')
c = mfilename('class')

 


Description


mfilename returns a string containing the file name of the most recently invoked function. When called from within the file, it returns the name of that file. This allows a function to determine its name, even if the file name has been changed.

p = mfilename('fullpath') returns the full path and name of the file in which the call occurs, not including the filename extension.

c = mfilename('class') in a method, returns the class of the method, not including the leading @ sign. If called from a nonmethod, it yields the empty string.
Tips


If mfilename is called with any argument other than the above two, it behaves as if it were called with no argument.

When called from the command line, mfilename returns an empty string.

To get the names of the callers of a MATLAB function file, use dbstack with an output argument.

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有