The Math Forum

Search All of the Math Forum:

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

Math Forum » Discussions » Software » comp.soft-sys.matlab

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  

Advanced Search

Back to Topic List Back to Topic List  

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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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.

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

% 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?

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.