I am attempting to create a function for the Fibonacci numbers using a for
loop. My code is as follows:
function fib = fibGenerator(N)
fib(1) = 0;
fib(2) = 1;
for i = 3:N
fib(i) = fib(i-1)+fib(i-2);
end
The following error message is displayed: Variable fib must be of data type uint32. It is currently of type double. Check where the variable is assigned a value.
I'm unsure of how to correct this.
Update
function fib = fibGenerator(N)
fibGenerator(1) = uint32(0);
fibGenerator(2) = uint32(1);
for i = 3:N
fibGenerator(i) = fibGenerator(i-1)+fibGenerator(i-2);
end