An increasing length vector error to find the last component (made through a loop)
2 views (last 30 days)
Show older comments
Hello all,
I have created a vector "X" with an initial value for "X1", through a loop, I am adding some other components to this vector. So, at the end of loop: for q=1:n
I should have a vector of length (n+1) for sure. However, for example for n=20, for some runs I have it correct and the vector is made OK. But, some another times that I push the run button (for the same code), I get the following error:
Attempted to access x1(6); index out of bounds because numel(x1)=5. or Attempted to access x1(10); index out of bounds because numel(x1)=9. or....
Do any of you know why? I mean why the result of this code is not consistent?
Regards, Mahdi
1 Comment
the cyclist
on 8 Apr 2014
Can you post the code? It is very difficult for us to guess the problem with out seeing it.
Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!