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

Thread Subject:
for loop problem

Subject: for loop problem

From: Sean Douglas

Date: 6 Aug, 2010 16:02:04

Message: 1 of 2

Hello, I have a for loop that is iterating every other number for some reason. I can’t figure out why. I put an i in the code right after the for loops first line and the output it is showing is saying that this for loop is counting up by 2’s. here’s the code, I think the really important info is the for loop but I will show you as much as I can incase having this for loop work with another for loop and being in a while loop could somehow make it count by 2’s.
    for i =(m+p):n;
          i % to check output
           buy= s2(i) ;
           buys2plot(end+1)=s2(i); axbuys2plot(end+1)=i;
           short=s(i); shorts1plot(end+1)=s(i); axshorts1plot(end+1)=i;
           date1=t(i); datevector1open(end+1)=t(i); datevectorindexo1=i;
           xx=1; flag=-1; dagger=1;
           sharesS2=s(i)/s2(i) ;
           buys1plot(end+1)=s(i); axbuys1plot(end+1)=i;
           short=s2(i); shorts2plot(end+1)=s2(i); axshorts2plot(end+1)=i;
           date2=t(i); datevector(end+1)=t(i); datevectorindexo2=i;
           xx=1; flag=-1; dagger=2;
                  break, %shoots out of next end( for i = m+p:n)
for p = y:n;
         %% CLOSE OUT 1

 …………………the while loop continues....
The output is showing that my indexing i’s in this for loop are all even numbers so my program is skipping the evaluation of every other data point.
Please help

Subject: for loop problem

From: Andy

Date: 6 Aug, 2010 16:13:04

Message: 2 of 2

You were receiving help for this problem in another post:

Please do not duplicate your posts.

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