Brethlosze
Brethlosze

Reputation: 1618

Matlab - Path to Function File calling a Function File

I have a function f0.m (the target, any function, not allowed to be modified) which calls a function f1.m (the command).

Inside f1.m I am needing to know the path of the caller function f0.m.

mfilename('fullpath') and S=dbstack('-completenames'); S(1).file gives the current file f1.m and matlab.desktop.editor.getActiveFilename gives the Active file in the editor (whatever it is).

What must I use for this?

Upvotes: 0

Views: 69

Answers (1)

Sardar Usama
Sardar Usama

Reputation: 19689

Use mfilename or dbstack inside f0 to get the path of f0.m. Pass the path of f0 as an input argument to 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

Upvotes: 1

Related Questions