matlab 获取当前文件所在路径的上一级路径

来源:互联网 发布:js延时函数sleep 编辑:程序博客网 时间:2024/05/29 21:16
used functions:

mfilename(): name of the current m-file
fileparts(): get the path string part
filesep: '/' or '\'
strfind(): find a substring from an objective string

code:

currentDepth = 1; % get the supper path of the current path
currPath = fileparts(mfilename('fullpath'));% get current path
fsep = filesep;
pos_v = strfind(currPath,fsep);
p = currPath(1:pos_v(length(pos_v)-currentDepth+1)-1); % -1: delete the last character '/' or '\' 
原创粉丝点击