help with error "Reference to a cleared variable n"

5 ビュー (過去 30 日間)
tyler hollings
tyler hollings 2020 年 9 月 15 日
コメント済み: tyler hollings 2020 年 9 月 15 日
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
x=create_array(1,n,1)
for i=1:n
x(i+2)=x(i)+x(i+1)
end
end
its having trouble with the variable n, also im calling a function inside this function so idk if this messes it up somehow?

採用された回答

the cyclist
the cyclist 2020 年 9 月 15 日
Putting
clear all
inside the function clears the variable n that you just sent into it. You don't need that line.
  1 件のコメント
tyler hollings
tyler hollings 2020 年 9 月 15 日
lol im an idiot sometimes i sweat haha thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by