From: "Bjorn Gustavsson" <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Running checkvars in the background
Date: Mon, 31 May 2010 14:26:03 +0000 (UTC)
Organization: Lancaster University
Lines: 36
Message-ID: <hu0gtr$83s$>
References: <htrl2f$3ks$> <>
Reply-To: "Bjorn Gustavsson" <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1275315963 8316 (31 May 2010 14:26:03 GMT)
NNTP-Posting-Date: Mon, 31 May 2010 14:26:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 19453
Xref: comp.soft-sys.matlab:640893

"" <> wrote in message <>...
> Dear Mike,
> Is there a way to turn on <checkvars> and have it run in the background until turned off? I
> tested one of my functions that I use all the time by inserting checkvars as the last line,
> and was amazed to find four instances of shadowing that involved three obscure Matlab
> functions such as Zb, and a function that I wrote years ago and had stupidly named G1.
> After the test I decided the shadowing was in these cases innocuous, and deleted
> checkvars. But it is obviously not practical to check all my functions this way. In many
> cases functions are deeply nested, and shadowing could have the potential to produce
> undetected errors. Ideally, checkvars would tell you the name of the m-file and the line
> number.
Mmaybe you can build something along these lines:

% At the top of your function:
persistent Checked_for_var_shadowing_yet

% Then at the end:
if ~exist('Checked_for_var_shadowing_yet')
  % want to test for two different calling variants
  Checked_for_var_shadowing_yet = [0,0];
if  ~all(Checked_for_var_shadowing_yet)
  % Something based on the input arguments:
  if nargin == 3
    Checked_for_var_shadowing_yet(1) = 1;
    Checked_for_var_shadowing_yet(2) = 1;