CaptainProg
CaptainProg

Reputation: 5690

Return a field from a function that returns a struct

I'm using the function dbstack to get the name of the currently executing function. dbstack returns a struct, with three fields: file, name and line. I'm only interested in name. Is there any way of returning just the name field when I call the dbstack function, or do I need to use two lines (the following)?

thisFunction = dbstack;
thisFunctionName = thisFunction.name;

Upvotes: 2

Views: 72

Answers (1)

Shai
Shai

Reputation: 114926

Your solution is the easiest (and propebly the best) way of doing what you want.

Alternatively, you can use getfield

>> thisFunctionName = getfield( dbstack, 'name' )

Upvotes: 4

Related Questions