help with error "Reference to a cleared variable n"
조회 수: 5 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!