Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
For Loop with two list items at a time rather that one

Subject: For Loop with two list items at a time rather that one

From: Alex

Date: 30 Jun, 2011 03:43:10

Message: 1 of 1

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?

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us