Thread Subject: Nested Function: Loop index set in child function

Subject: Nested Function: Loop index set in child function

From: Karl Trumstedt

Date: 10 Aug, 2007 10:36:39

Message: 1 of 3

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.

Subject: Nested Function: Loop index set in child function

From: Loren Shure

Date: 10 Aug, 2007 11:40:35

Message: 2 of 3

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
http://blogs.mathworks.com/loren/

Subject: Nested Function: Loop index set in child function

From: Michael Wild

Date: 10 Aug, 2007 12:17:59

Message: 3 of 3

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...


michael

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
nested function Karl Trumstedt 10 Aug, 2007 06:40:10
loop index Karl Trumstedt 10 Aug, 2007 06:40:10
child function Karl Trumstedt 10 Aug, 2007 06:40:10
rssFeed for this Thread

Public Submission Policy

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.

Contact us at files@mathworks.com