2 IF loops inside of a FOR loop!
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
David Goodmanson
on 2 Oct 2016
without delving into code details, you have to be a bit careful with the 'continue' command. It is designed to skip to the 'for' loop. Would deleting the 'else continue' line accomplish what you want?
Image Analyst
on 2 Oct 2016
It's no longer like that in his updated code in the comments to me below.
David Goodmanson
on 2 Oct 2016
Well, OK, but it sure looks like it is still there in the only code I could find below. I must be missing something.
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.
Sherwin
on 3 Oct 2016
Answers (1)
Image Analyst
on 2 Oct 2016
0 votes
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
I have no idea if you want minichrom and counter to be functions of row, column, or spot length. What is spot length? Do you have an image of spots? Attaching a diagram or image or screenshot would be helpful. Have you learned how to step through with the debugger yet?
Sherwin
on 2 Oct 2016
Edited: Image Analyst
on 2 Oct 2016
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.
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!
