I'm trying out nested functions and get a warning in my for-
loops:
Outer index '.' is set inside of a child function.
Thanks to the shared workspace it is possible to destroy
these indices. Can I specify that a variable should become
specific for a function and not shared? An easy solution is
of course to rename the index, but I'd rather have the
regular i,j,k etc.
Subject: Nested Function: Loop index set in child function
In article <f9hf3n$d5j$1@fred.mathworks.com>, karltru@gmail.com says...
> Hi,
>
> I'm trying out nested functions and get a warning in my for-
> loops:
>
> Outer index '.' is set inside of a child function.
>
> Thanks to the shared workspace it is possible to destroy
> these indices. Can I specify that a variable should become
> specific for a function and not shared? An easy solution is
> of course to rename the index, but I'd rather have the
> regular i,j,k etc.
>
There's no way besides changing the name to limit the scope of the
variable. Except... you can force it to be local in the nested function
if you pass it in as an input. But this makes the calling syntax quite
artificial.
Loren Shure wrote:
> In article <f9hf3n$d5j$1@fred.mathworks.com>, karltru@gmail.com says...
>> Hi,
>>
>> I'm trying out nested functions and get a warning in my for-
>> loops:
>>
>> Outer index '.' is set inside of a child function.
>>
>> Thanks to the shared workspace it is possible to destroy
>> these indices. Can I specify that a variable should become
>> specific for a function and not shared? An easy solution is
>> of course to rename the index, but I'd rather have the
>> regular i,j,k etc.
>>
>
> There's no way besides changing the name to limit the scope of the
> variable. Except... you can force it to be local in the nested function
> if you pass it in as an input. But this makes the calling syntax quite
> artificial.
>
and that's one of the reasons why i don't like implicit variable
declarations. apart from the occasional typo resulting in hard to find
errors...
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central.
Read the complete Disclaimer prior to use.