Path: news.mathworks.com!not-for-mail
From: "Bjorn Gustavsson" <bjonr@irf.se>
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$1@fred.mathworks.com>
References: <htrl2f$3ks$1@fred.mathworks.com> <2019061764.250670.1275239223055.JavaMail.root@gallium.mathforum.org>
Reply-To: "Bjorn Gustavsson" <bjonr@irf.se>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1275315963 8316 172.30.248.37 (31 May 2010 14:26:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 31 May 2010 14:26:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 19453
Xref: news.mathworks.com comp.soft-sys.matlab:640893

"freund@mail.biu.ac.il" <freund@mail.biu.ac.il> wrote in message <2019061764.250670.1275239223055.JavaMail.root@gallium.mathforum.org>...
> 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];
end
if  ~all(Checked_for_var_shadowing_yet)
  
  checkvars
  % Something based on the input arguments:
  if nargin == 3
    Checked_for_var_shadowing_yet(1) = 1;
  else
    Checked_for_var_shadowing_yet(2) = 1;
  end
end

HTH,
Bjeorn