MATLAB Answers

help with error "Reference to a cleared variable n"

4 views (last 30 days)
im trying to make a series that gives me n terms of the fibonaci series, ive got it to work like the pure code but now its having troble once i put it into a funtion file
function x = fib(n)
close all
clear all
for i=1:n
its having trouble with the variable n, also im calling a function inside this function so idk if this messes it up somehow?

Accepted Answer

the cyclist
the cyclist on 15 Sep 2020
clear all
inside the function clears the variable n that you just sent into it. You don't need that line.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by