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 Problem
Replies: 2   Last Post: Feb 13, 2013 9:22 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Jos

Posts: 1,266
Registered: 10/24/08
Re: For Loop Problem
Posted: Feb 13, 2013 9:22 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Pete " <harri.short@hotmail.com> wrote in message <kfg5d3$6k6$1@newscl01ah.mathworks.com>...
> Hi,
> I am trying to use a For Loop to assign each individual number in a 31x1 matrix a letter. I have tried to create a For loop but i keep getting an error saying that it cannot label the point as there are not enough points in the matrix, i.e there are 31 numbers in the matrix and it is trying to find the 32nd. What am i doing wrong? Here is what i have at the moment:
>
> for j=1:length(Tr)
> A=Tr(j);
> B=Tr(j+1);
> end
>
> Thanks


In the line B=Tr(j+1) you want to retrieve the "j+1"-th element of Tr. If j reached the value of length(Tr), Tr(j) is the last element, but there is no Tr(j+1) element anymore, of course.
This is causing the error.

~ Jos


Date Subject Author
2/13/13
Read Re: For Loop Problem
Jos
2/13/13
Read Re: For Loop Problem
Steven Lord

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.