简体   繁体   English

运行 Octave 函数 - 在第 1 行第 5 列附近未定义

[英]Running Octave function - undefined near line 1 column 5

I got a problem with running any Octave function.我在运行任何 Octave 函数时遇到问题。 The function can be as simple as:该函数可以很简单:

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

named testt.m and called with commander命名为 testt.m 并与指挥官通话

a = testt(7) a = testt(7)

gives an error: 'testt' undefined near line 1 column 5给出错误:'testt' 在第 1 行第 5 列附近未定义

I added path before addpath(pwd).我在 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?有人帮忙吗?

It will work fine if you add 'addpath(pwd)' before declaring the function.如果在声明函数之前添加 'addpath(pwd)',它将正常工作。 here is your refined code which worked in my octave 4.2.1这是您在我的八度音阶 4.2.1 中使用的精炼代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM