Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
parfor question

Subject: parfor question

From: Kirk

Date: 1 Sep, 2009 20:14:09

Message: 1 of 4

I have a m file script that repeats several uses of "parfor" with diferent calls in each . Therefor I use the variable "i" several times. However I am getting the error:

"The index variable "i" is used after the PARFOR loop, but it is unavailable after the loop"

Any suggestions would be appreciated.

My usage looks like:

parfor i = 1:5
  some statements;
end;

parofor i = 1:5
  some other statments;
end;

Subject: parfor question

From: Edric M Ellis

Date: 2 Sep, 2009 08:14:54

Message: 2 of 4

"Kirk" <kwythers.nospam@umn.edu> writes:

> I have a m file script that repeats several uses of "parfor" with diferent
> calls in each . Therefor I use the variable "i" several times. However I am
> getting the error:
>
> "The index variable "i" is used after the PARFOR loop, but it is unavailable after the loop"

That message means that you must have something more like the following:

parfor i = 1:10
  < stuff >
end

disp(i) % or use it in some other way

This is not allowed, because the index variable cannot be defined after the
PARFOR loop. The reason is that the iterations of the PARFOR loop are performed
in a non-deterministic order, so there's no reasonable value for "i" outside the
PARFOR loop.

It is fine to do this (with no other statements referring to "i"):

parfor i=1:10
    x(i) = i;
end
parfor i=1:10
    y(i) = i;
end

Cheers,

Edric.

Subject: parfor question

From: Kirk

Date: 2 Sep, 2009 14:46:04

Message: 3 of 4

 
> It is fine to do this (with no other statements referring to "i"):
>
> parfor i=1:10
> x(i) = i;
> end
> parfor i=1:10
> y(i) = i;
> end

Thanks for the suggestion. The issue I face however, it that I am repeating several hundred instances of parfor is this script. Each performs the same function except the <stuff> part of the parfor loop grab a different parameter file. If I set a new variable to equal i, I would have to go through the alphabet several times with variables names like aa, ab, ac....

Subject: parfor question

From: George Coles

Date: 17 Dec, 2009 00:35:24

Message: 4 of 4

"Kirk" <kwythers.nospam@umn.edu> wrote in message <h7m0fc$kjb$1@fred.mathworks.com>...
>
> > It is fine to do this (with no other statements referring to "i"):
> >
> > parfor i=1:10
> > x(i) = i;
> > end
> > parfor i=1:10
> > y(i) = i;
> > end
>
> Thanks for the suggestion. The issue I face however, it that I am repeating several hundred instances of parfor is this script. Each performs the same function except the <stuff> part of the parfor loop grab a different parameter file. If I set a new variable to equal i, I would have to go through the alphabet several times with variables names like aa, ab, ac....

=>willl calling
clear i
between parfor loops help?

Tags for this Thread

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.

Contact us