How to call m file directly from another m file in MATLAB without adding folder path

How to call m file from another m file in MATLAB without adding folder path? I do not want to add my folder through

addpath(genpath(''))
0
source share
2 answers

All visibility rules for functions are based on folders. If you want to have different capabilities, you need to place your functions in different folders.

Generally, avoiding duplicate function names and just adding all the source files to your search path is what works. To avoid duplicate function names, you can take a look at the packages.

+1
source

MATLAB run , cd , .

:

% testcode.m
function [output] = testcode(fullfunctionpath, A, B)
[pathname, functionName] = fileparts(fullfunctionpath);
olddir = cd(pathname);

output = feval(functionName, A, B);
cd(olddir);
end

% .\test\testing.m
function [output] = testing(A, B)
output = A + B;
end

:

C = testcode('C:\testcode-matlab\test\testing.m', 1, 2);

C =

     3

, , . , , MATLAB . . .

+3

Source: https://habr.com/ru/post/1627306/


All Articles