You can, call local functions externally if you set up a bunch of function handles. Not that I recommend this, but I got this setup from a colleague. This code is not robust -- there are almost certainly cases where it'll fail or do bad things.
% code to create callable handles for all subfuncs in some file
%
% first, in the file containing subfuncs:
% this is the "setup" main func
function [p]=To_Call_Subfuncs()
[p,n]=update_function_list();
end
% this creates all the handles by pseudogrepping the subfunction names
function [p,function_names]=update_function_list()
function_names={};
% making p empty allows one to call, e.g. funclist.firstfunc()
p=[];
f=fopen([mfilename() '.m'],'r');
while ~feof(f),
line=fgetl(f);
s= strfind( strtrim(line),'function ') ;
if length(s) && s(1)==1,
s0=find(line=='=');
s1=find(line=='(');
if length(s0)==0,s0=9;end;
if(length(s1)==0), s1 = numel(line)+1;end; %to handle the -1 later on
function_name= strtrim( [line(s0(1)+1:s1(1)-1)] );
if length(function_name),
function_names{end+1}=function_name;
eval( sprintf('p.%s=@%s;', function_name, function_name) );
end;
end;
end;
end
%
%follow this with the functions we actually want to call
function a = firstfunc(x)
a=x;
end
function b = secondfunc(x)
b = x^2;
end
function cnot = thirdfunc
cnot= 17;
end
%
%
% next, in the m-file where some function is calling these subfuncs,
% set up the handles with:
% run(fullfile(dirpath,'the_mfile.m'))
% the_mfile=ans;
% because I don't think run() returns a value --
%% only the called mfile does.
% now you can call the_mfile.firstfunc() and so on.
func1(x)is more naturally in Matlab than doingperform('func1', x). Perhaps a package would be better?