2 IF loops inside of a FOR loop!
1 view (last 30 days)
Show older comments
Hi, I have 2 IF loops inside of a FOR loop.
for z = 1:spot_length;
if minichrom(1,z) == 0
counter = counter + 1;
if counter >= MaxH(i,j)
minichrom(1,z+1) = 1;
else continue
end
else counter(j,:) = 0;
end
After the inside "ELSE continue", the loop seems to skip to the FOR loop instead of the exterior IF and "counter" value is added up. Would you please help me?
5 Comments
Image Analyst
on 2 Oct 2016
Oh, you're right. He just split it into 2 lines now (like I recommended in my answer) so I overlooked it.
Answers (1)
Image Analyst
on 2 Oct 2016
Usually you don't have a semicolon on the end of the for line. And usually you don't put code on the else line. Why does counter take row and column indexes some times but at other times you treat it as a scalar instead of a 2-D matrix???
I don't know what you mean by it seems to skip to the for loop instead of doing the if. Exactly where is it when it "skips" to the for loop? And what part of the for loop? Do you know how to use the debugger? If not, see this: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/ When you know how to use that, which you WILL need to learn, then you can step line by line examining variables to see what they are and what might cause the code to skip to some part of the code or enter or not enter a "for" loop or an "if" statement. You'll need to do that because we don't know what the values of minichrome are and your explanation is ambiguous.
5 Comments
Image Analyst
on 2 Oct 2016
Explain how you could get 6, 7, or 8 zeros consecutively in a minichrom that is only 5 elements long? Shouldn't the values of MaxH be no bigger than 5? I mean, once all 5 elements of a minichrom are 0, then you can't add more to make 6, 7, or 8 since the minichrom vector is only 5 long. Please explain.
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!