return function name, not m-file name

Discussion in 'MATLAB' started by Mike Blatchley, Aug 10, 2006.

  1. I know that mfilename will return the name of the current .m file
    running. But, if I have multiple function definitions within this
    file, how can I return the name of the function that is running?

    Thanks,
    Mike
     
    Mike Blatchley, Aug 10, 2006
    #1
    1. Advertisements

  2. There might be another way to do this, but this should work too:

    Make a temporary variable within each function:
    temp = 1;
    a = whos;
    functionName = a.nesting.function

    The above will return the name of the current function and store it
    in the variable functionName.

    HTH
    -Shardul
     
    Shardul Bhatia, Aug 10, 2006
    #2
    1. Advertisements

  3. You can use the DBSTACK function with two output arguments.

    Thank you,

    Johnson Smith
    The MathWorks, Inc.
     
    Johnson Smith, Aug 10, 2006
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.