MATLAB: Generating Fibonacci Sequence Using While Loop

fibonacciloopMATLABsequencewhile

Hello all,
I am trying to generate the first Fibonacci Sequence Term greater than 1000 using a while loop. I am using the following code:
fibf(1) = 1;
fibf(2) = 1;
n=3:50;
while fibf(n) < 1000
fibf(n) = fibf(n-1)+fibf(n-2);
end
I am getting the error, 'Index exceeds matrix dimensions'. Any help is appreciated

Best Answer

fibf(1) = 1;
fibf(2) = 1;
n=3
while fibf(n-1) < 1000
fibf(n) = fibf(n-1)+fibf(n-2);
n=n+1;
end