Determine current stack level

조회 수: 5 (최근 30일)
Jim Hokanson
Jim Hokanson 2012년 5월 26일
The goal is to be able to write a function which opens the editor to the current stack level. This is fairly easy to do for the top of the stack but more difficult if the current stack level is changed, such as via the use of dbup and dbdown. Opening the editor to a file at a specific line is fairly easy using, matlab.desktop.editor.openAndGoToLine. The difficult part is determining the level.
The simple solution is to do the following:
[s,I] = dbstack('-completenames');
matlab.desktop.editor.openAndGoToLine(s(I).file,s(I).line)
I don't like that this creates variables in the workspace and that it is so long. Ideally, I want to have a simple command like this:
open2ws
Some problems:
  • called functions get added to the top of the stack, not to the current workspace, so calling a function erases any information of where you were in dbstack
  • mfilename doesn't work on the current stack level, but on the top of the stack
The best solution I have is: eval(open2ws), where open2ws passes a string with the function whos in it, and the nesting information in whos can be used to identify the current function (I think). Any cleaner suggestions?

답변 (0개)

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by