Help with if statements and looping
Info
This question is closed. Reopen it to edit or answer.
Show older comments
The goal of the below code is for the value retrieved from treelineBPsReversed to be lowered with each iteration of the IF statement, so that the first value below the endPoints(x) value that it is being tested against with > causes the desired data to be recorded in 'segment'.
endPoints = [974;1281;1637;1819]
treelineBPsReversed = [1626;1124;359]
segment = zeros(length(endPoints),3);
treelineBPsReversed = flipud(treelineBPs);
for x = 1:length(endPoints)
counter = 1;
if endPoints(x) > treelineBPsReversed(counter)
segment(x,3) = alldistancesMatrix(treelineBPsReversed(counter),endPoints(x));
segment(x,1) = treelineBPsReversed(counter);
segment(x,2) = endPoints(x);
else endPoints(x) < treelineBPsReversed(counter);
counter = counter+1;
continue
end
end
I am trying to get control returned to this IF statement after it runs through the first time, but it's not working. I may have a fundamental misunderstanding of how IF statements and continue work, but scouring webpages on this site and others have not helped me realize what's wrong.
Please let me know what can be done to "loop through" the IF statement, as right now it is read through only once, before going onto the next FOR loop iteration.
Thanks, Luke
Answers (2)
Azzi Abdelmalek
on 2 Jun 2013
It's not else endPoints(x) < treelineBPsReversed(counter);
it should be
else if endPoints(x) < treelineBPsReversed(counter);
1 Comment
Image Analyst
on 2 Jun 2013
I tranferred Luke's "Answer" here because it should have been a comment to Azzi:
"Thanks, but that still doesn't stop it from starting another iteration of the FOR loop before going hitting the IF statement again."
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!