سؤال

I have written this to determine the n-th Fibonacci number:

function f=fibfun(n)

if n>2
  f=fibfun(n-1)+fibfun(n-2);
else
  f=1;
end

It should work but it doesn't. If I type fibfun(10) then the answer should be 55. But all I get is:

Undefined function 'fibfun' for input arguments of type 'double'.

What does this mean? What am I doing wrong?

هل كانت مفيدة؟

المحلول

It means that MATLAB can't find your function - the directory where you saved the file fibfun.m should either be the current directory or defined in your MATLAB path.

نصائح أخرى

Make sure the file is on your current path.

Use:

addpath(genpath('/path/to/file/'));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top