Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

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  
Alex

Posts: 22
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.
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?



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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.