Need help with this Matlab script question? For loop!!
Ältere Kommentare anzeigen
I keep getting this error 'Attempted to access x(3); index out of bounds because numel(x)=2.' It's really frustrating!!!
Akzeptierte Antwort
Weitere Antworten (1)
Robert Cumming
am 29 Jul. 2014
Bearbeitet: Robert Cumming
am 29 Jul. 2014
It the start of your while loop the condition includes a check on x(3), hence why you get the error.
edit: you could fix it this way:
while true
x(k) = x(k-1) + x(k-2);
k = k+1;
if (abs(x(k)./x(k-1) - x(k-1)./x(k-2))>0.001)
break
end
end
1 Kommentar
Dylan Flores
am 29 Jul. 2014
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!