我正在使用函数dbstack
来获取当前正在执行的函数的名称。 dbstack
返回一个结构,其中包含三个字段:file
,name
和line
。我只对name
感兴趣。当我调用name
函数时,有没有办法返回 dbstack
字段,还是需要使用两行(以下)?
thisFunction = dbstack;
thisFunctionName = thisFunction.name;
答案 0 :(得分:4)
您的解决方案是最简单(也是最好)的方式,可以满足您的需求。
或者,您可以使用getfield
>> thisFunctionName = getfield( dbstack, 'name' )