Calling local functions from the command line

I have a local function defined in m file. For instance:

% begining of public_function.m file function fh = public_function( ) % % do some computation... fh = @local_function; % return function handle to local function defined below function y = local_function( x ) % % a local function inside public_function.m file % % some manipulation on x y = x; % end of public_function.m file NOTE THAT local_function is NOT nested 

Now I would like to call local_function from the command line (and not from public_function ). I was able to do this using the function descriptor returned from public_function :

 >> fh = public_function(); % got handle to local_function >> y = fh( x ); % calling the local function from command line :-) 

My question is:
Is there any other way (besides explicitly passing the function descriptor) to call a local function from the command line (or another m file / functions)?

More precisely, I want the method to have access to any local function in the file (provided that I know its name). So, if I have a public_function.m file (and function), and I know that local_function is local to this file, is there a way to access local_function from the command line?

+6
source share
1 answer

The official documentation states that:

... you cannot call a local function from the command line or from functions in other files.

Accordingly, you must pass your handle to the caller to allow him to indirectly touch his m file. I believe that otherwise there is no documented way to access local functions.

Oddly enough, you can still do this with help :

 help public_function>local_function 
+4
source

All Articles