2 IF loops inside of a FOR loop!

조회 수: 1 (최근 30일)
Sherwin
Sherwin 2016년 10월 2일
댓글: Sherwin 2016년 10월 3일
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
Image Analyst
Image Analyst 2016년 10월 2일
Oh, you're right. He just split it into 2 lines now (like I recommended in my answer) so I overlooked it.
Sherwin
Sherwin 2016년 10월 3일
Yes, I did. But still the indices of "minichrom" and "counter" are wrong. Would you please help me correct them?

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2016년 10월 2일
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
Image Analyst
Image Analyst 2016년 10월 2일
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.
Sherwin
Sherwin 2016년 10월 2일
편집: Sherwin 2016년 10월 2일
Oh I'm sorry. The image shows a small sample, the actual size of the big matrix is 4*960 in the code, and it has minichroms with length of 60, and 16 columns. I couldn't make a matrix of that size. I just wanted to show what is a minichrom or spot and the size of MaxH matrix and that the generation should be done for each minichrom.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by