From: Matt Fig on
Is there any way you could provide a copy-and-paste version of you code (a good and standard practice by the way), because I cannot duplicate your issue because of variables I don't have access to. Pare it down and you may get more help.
From: Jan Simon on
Dear Andy,

> Jan's referring to this part of your code:
> for i =(m+p):n;
> % snip
> end
> y = i+1
> The comment was that you should not try to access the loop counter i outside of the loop. It is NOT the case, however, that y will necessarily get set to n here, because of the break.

Thanks! I've overlooked the BREAK. Jan
From: Jan Simon on
Dear Sean,

> while(m+p<=n)
> for i =(m+p):n;
> disp(i);
> end
> end

I hope the debugger showed you what's going on already.

What about this theory:
Looking at these lines, it is clear, that the FOR loop is processed in steps of 1. But you break the FOR loop in the first iteration and then obviously m or p are increased by 2 (or both by 1).

Jan
From: Sean Douglas on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i3hm1p$30c$1(a)fred.mathworks.com>...
> Dear Sean,
>
> > while(m+p<=n)
> > for i =(m+p):n;
> > disp(i);
> > end
> > end
>
> I hope the debugger showed you what's going on already.
>
> What about this theory:
> Looking at these lines, it is clear, that the FOR loop is processed in steps of 1. But you break the FOR loop in the first iteration and then obviously m or p are increased by 2 (or both by 1).
>
> Jan

Hey guys,
Jan i found something that makes me think it is not what you suggested in your last post....When I made a simpler version of my code to post, the problem went away, of course right. So that part of the code seems ok becuase i used that same method. I have now figured out it has something do with the spread1 variable, at least very related to it. This Spread1 variable is what helps decide if the 'if statement' is met here is the line with the Spread1 variable from my ealier post.
if((s(i)/Mc(i)-s2(i)/Mc2(i)>spread1)&&(flag==1))

if I make the spread 1 variable large enough to that the if statment is never met the i's iterate correclty, however if I make the spread1 variable less than about 1 where the if statment condition is met, the 'for loop' iterates every other one still.

Ofcourse in my simpler code it works no matter what i make spread1 equal to, the simple code works...
any suggestions as to why my actual code would iterate correctly when the conditions are never met or when spread1 is set greater than 1? or why it iterates every other i once a the condition is met?

From: Jan Simon on
Dear Sean,

what did the debugger tell you ?!

If you use an offically released Matlab version and your computer is not damaged or magic, the FOR loop will *not* increase i by 2.

while(m+p<=n)
disp('*** I start the FOR loop now');
for i =(m+p):n;
fprintf('== i is %g\n', i)
if((s(i)/Mc(i)-s2(i)/Mc2(i)>spread1)&&(flag==1))
...
end
end % FOR i
end % while m+p <= n

Please take the time to insert at least these two lines to display, when the FOR loop is started and when i is increased in the inner FOR loop. Matlab is for sure exactly doing, what you have commanded:
for i = (m+p):n
increases i by 1 in every *performed* iteration.

Kind regards, have fun with the debugger, Jan