File Exchange

image thumbnail

me: call self in recursive way but independent of mfilename

version 1.0.1 (1.15 KB) by raym
With argument,this funciton call the mfilename that it was located in, in an recursive way and can retrieve output.

1 Download

Updated 28 May 2020

View Version History

View License

============
With argument,this funciton call the mfilename that it was located in, in an recursive way and can retrieve output.

function myFun (a,b)
...
me(1,2); % me is equal to myFun

end

===============
If no argument, this function returns a handle to mfilename.

function myFun (a,b)
...
aFun = me; % aFun is equal to myFun
aFun(1,2);

end

In this way, no matter how the function name is changed, there is no need to update recursive fucntion in the main contex.

Cite As

raym (2021). me: call self in recursive way but independent of mfilename (https://www.mathworks.com/matlabcentral/fileexchange/76323-me-call-self-in-recursive-way-but-independent-of-mfilename), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (1)

Stephen Cobeldick

It is simple and more efficient to just make the recursive function a local function. Then the mfilename / main function name is totally irrelevant.

MATLAB Release Compatibility
Created with R2020a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!