Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Determine current stack level

Asked by Jim Hokanson on 26 May 2012

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 Comments

Jim Hokanson

Products

No products are associated with this question.

0 Answers

Contact us