2
votes

I got a problem with running any Octave function. The function can be as simple as:

function a = testt(k)
  a = k + 5
end

named testt.m and called with commander

a = testt(7)

gives an error: 'testt' undefined near line 1 column 5

I added path before addpath(pwd). I copied some available function from web. And it is still the same. At the same time I'm able to run another function which I wrote two days ago and which is in the same directory:

    function A = fibn_(n)

    B = [0 1];

    for i = 1: n-2

      nkol = size(B,2);
      minus = B(1,nkol);
      minus1 = B(1,nkol-1);

      B(1,nkol+1) = minus1 + minus;

    end;

    A = B;

    end;

I have no idea what is the difference between this two (not only this two but also many other functions that seems to be correct).

Anybody help?

1
Did you make sure to save the file with a .m at the end? - Suever
Have you named your file testt.m? - Andy
Yes, I named it testt.m - Prze Gee
And pwd shoes the folder with the testt.m file, and dir shows the file? - Nick J

1 Answers

2
votes

It will work fine if you add 'addpath(pwd)' before declaring the function. here is your refined code which worked in my octave 4.2.1

addpath(pwd)
function a = testt(k)
a = k + 5
end
a = testt(7)