首页 > 解决方案 > Matlab - 调用函数文件的函数文件的路径

问题描述

我有一个调用函数(命令)的函数f0.m(目标,任何函数,不允许修改)。f1.m

在里面f1.m我需要知道调用者函数的路径f0.m

mfilename('fullpath')S=dbstack('-completenames'); S(1).file给出当前文件f1.mmatlab.desktop.editor.getActiveFilename在编辑器中给出活动文件(无论它是什么)。

我必须为此使用什么?

标签: matlabpath

解决方案


使用mfilenameor dbstackinsidef0获取f0.m. 将 的路径f0作为输入参数传递给f1.

function out_f0 = f0(inp_f0)
%whatever you have in here
f0path = mfilename('fullpath');
out_f1 = f1(inp_f1, f0path);
%...
end

function out_f1 = f1(inp_f1, f0path)
%whatever you have in here
end

推荐阅读