Prev: imwrite image in an array
Next: CONVERT
From: Cygnine on 8 Feb 2010 23:07 I'm running Matlab R2008b. I would like to be able to determine whether a current workspace is the 'base' workspace. ('base' in the same context as the assignin and evalain statements.) For example, I'd like to run something like >> which_space_am_i_in() and have it return 'base', or true, or something indicating the command-line workspace versus some workspace inside a function. The basic functionality I'm looking for is I want a function to act differently depending if it's called from the command line (could be a script run from the command line) or from some other function. Are there any builtin functions or simple ways to do this?
From: Doug Schwarz on 8 Feb 2010 23:11 In article <hkqn18$ni2$1(a)fred.mathworks.com>, "Cygnine " <cygnine(a)remove.this.gmail.com> wrote: > I'm running Matlab R2008b. I would like to be able to determine whether a > current workspace is the 'base' workspace. ('base' in the same context as the > assignin and evalain statements.) > > For example, I'd like to run something like > > >> which_space_am_i_in() > > and have it return 'base', or true, or something indicating the command-line > workspace versus some workspace inside a function. > > The basic functionality I'm looking for is I want a function to act > differently depending if it's called from the command line (could be a script > run from the command line) or from some other function. > > Are there any builtin functions or simple ways to do this? Check out dbstack. -- Doug Schwarz dmschwarz&ieee,org Make obvious changes to get real email address.
From: Cygnine on 8 Feb 2010 23:24 Doug Schwarz <see(a)sig.for.address.edu> wrote in message > Check out dbstack. Well, it's less elegant than I would've hoped, but I guess (length(dbstack)==1) provides a reasonable logical test. Thanks for the info.
From: Steven Lord on 9 Feb 2010 10:01 "Cygnine " <cygnine(a)remove.this.gmail.com> wrote in message news:hkqn18$ni2$1(a)fred.mathworks.com... > I'm running Matlab R2008b. I would like to be able to determine whether a > current workspace is the 'base' workspace. ('base' in the same context as > the assignin and evalain statements.) > > For example, I'd like to run something like > >>> which_space_am_i_in() > > and have it return 'base', or true, or something indicating the > command-line workspace versus some workspace inside a function. > The basic functionality I'm looking for is I want a function to act > differently depending if it's called from the command line (could be a > script run from the command line) or from some other function. Okay, I'll bite -- what's your use case? What should your function do differently if called from the command line than if it's called from a function? -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: Matt J on 9 Feb 2010 10:33
Here's what I use, but beware trying to using it in debug mode. The dbstack command is insensitive to dbup/dbdown etc... function where %The current location in the function stack [s,wsi]=dbstack('-completenames') ; str='In base workspace'; if length(s)>1, str=s(2).file; end disp(' '); disp([' ' str]); disp(' '); |