Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: For Loop with two list items at a time rather that one
Replies: 0

 Alex Posts: 24 Registered: 2/11/11
For Loop with two list items at a time rather that one
Posted: Jun 29, 2011 11:43 PM

Is there a way to make a for loop use two items from it's list in every iteration? I need the 1st and 2nd value, then the 3rd and 4th, and so on from the list they are stored in.
I have a scenario where I have a (possible large) list of X locations from a graph that are significant to me, and I want to collect the data between 2 of the points automatically.
ex:

changepoint = [8 61 147 218 381 472 533 552]

c((changepoint(1)+1):(changepoint(2)-1))
% c((8+1):(61-1)) since changepoint(1) = 8, and changepoint(2) = 61, reducing to:
% c(9:60) This is what I want, as well as:
% c(148:217)
% c(382:471)
% c(534:551)

% Where c is my original data, and I want to find the values between the
% 1st changepoint and the 2nd, then the data between the 3rd changepoint
% and the 4th, between the 5th and 6th, and so on.
% Can I automate this with a for loop?