2 IF loops inside of a FOR loop!

1 vue (au cours des 30 derniers jours)
Sherwin
Sherwin le 2 Oct 2016
Commenté : Sherwin le 3 Oct 2016
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 commentaires
Image Analyst
Image Analyst le 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
Sherwin le 3 Oct 2016
Yes, I did. But still the indices of "minichrom" and "counter" are wrong. Would you please help me correct them?

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 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 commentaires
Image Analyst
Image Analyst le 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.
Sherwin
Sherwin le 2 Oct 2016
Modifié(e) : Sherwin le 2 Oct 2016
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by