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 trouble need help!!!

Subject: for loop trouble need help!!!

From: daniel

Date: 17 Oct, 2010 01:56:03

Message: 1 of 4

I am having trouble creating a vector through the use of this for loop.

for i =200:330
    y2(i+1)= d * (( 10*((i-200)^3))/(130^3)) - ((15*((i-200)^4))/(130^4)) + ((6*((i-200)^5))/(130^5));
end

The problem is that when I try to graph the vector there are values for the vector from 0-200. the values are zero by the way. Is there any way i can fix this?

Subject: for loop trouble need help!!!

From: Ross W

Date: 17 Oct, 2010 02:16:03

Message: 2 of 4

"daniel " <dam002@ucsd.edu> wrote in message <i9dl3j$e8t$1@fred.mathworks.com>...
> I am having trouble creating a vector through the use of this for loop.
>
> for i =200:330
> y2(i+1)= d * (( 10*((i-200)^3))/(130^3)) - ((15*((i-200)^4))/(130^4)) + ((6*((i-200)^5))/(130^5));
> end
>
> The problem is that when I try to graph the vector there are values for the vector from 0-200. the values are zero by the way. Is there any way i can fix this?


It's not clear what you want instead of the current result. How about this:
change
y2(i+1)=...
to
y2(i+1-200)=...

Ross

Subject: for loop trouble need help!!!

From: daniel

Date: 17 Oct, 2010 02:29:05

Message: 3 of 4

"Ross W" <rosswoodskiwi@hotmail.com> wrote in message <i9dm93$rot$1@fred.mathworks.com>...
> "daniel " <dam002@ucsd.edu> wrote in message <i9dl3j$e8t$1@fred.mathworks.com>...
> > I am having trouble creating a vector through the use of this for loop.
> >
> > for i =200:330
> > y2(i+1)= d * (( 10*((i-200)^3))/(130^3)) - ((15*((i-200)^4))/(130^4)) + ((6*((i-200)^5))/(130^5));
> > end
> >
> > The problem is that when I try to graph the vector there are values for the vector from 0-200. the values are zero by the way. Is there any way i can fix this?
>
>
> It's not clear what you want instead of the current result. How about this:
> change
> y2(i+1)=...
> to
> y2(i+1-200)=...
>
> Ross



I want the values from y2(200) to y2(300). When I check the values of the vector there are values for y2(0) to y2(200) which are all zero.

Subject: for loop trouble need help!!!

From: Roger Stafford

Date: 17 Oct, 2010 03:22:03

Message: 4 of 4

"daniel " <dam002@ucsd.edu> wrote in message <i9dl3j$e8t$1@fred.mathworks.com>...
> .......
> The problem is that when I try to graph the vector there are values for the vector from 0-200. the values are zero by the way. Is there any way i can fix this?
- - - - - - - - -
  In matlab all vectors start with the index 1. If you place an entry at index 201 matlab will always create space for elements from 1 to 200 as well and initially these will be set to zeros, as you have already found. That is something you will have to live with if you use matlab.

  When plotting you could always use something like y2(201:331), but the elements from 1 to 200 would represent something of a waste because they occupy memory space on your computer. Why not adjust your definition of the indices to match that of matlab?

  Also you are mistaken when you speak of y2(0). In matlab you cannot have a 0 for an index.

Roger Stafford

Tags for this Thread

No tags are associated with 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