Help with if statements and looping

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)

It's not else endPoints(x) < treelineBPsReversed(counter);
it should be
else if endPoints(x) < treelineBPsReversed(counter);

1 Comment

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."
Luke
Luke on 2 Jun 2013
I got it working with the help of an IRL friend. The IF needed to be within its own FOR loop in order for it to do what I wanted it to do.

This question is closed.

Asked:

on 2 Jun 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!