An increasing length vector error to find the last component (made through a loop)

3 次查看(过去 30 天)
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

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by