八度嵌套函数 "not implemented" 错误

Octave nested functions "not implemented" error

我的octave老是报错:

nested functions not implemented in this context
>>>   function nested1

nested functions not implemented in this context
>>>   function nested1

作为对以下代码(名为 test.m 的文件)的反应:

clear -all;
clc;

function test
  function nested1
    disp('nested 1')
  end

  function nested2
    disp('nested2')
  end

  nested1()
  nested2()
end

我只是不明白。怎么了?

试试下面的代码:

function test
   nested1
   nested2

   function nested1
      disp('nested 1')
   end

   function nested2
      disp('nested 2')
   end
end

好吧,实际问题是我将这段代码写在脚本文件中。我真正要做的是把它变成函数文件。

所以。错误代码如下所示:

clear -all; 
clc;

function test
  function nested1
     disp('nested 1')
  end

  function nested2
     disp('nested 2')
  end

   nested1
   nested2
end

工作的是

function test
  function nested1
     disp('nested 1')
  end

  function nested2
     disp('nested 2')
  end

   nested1
   nested2
end

包加载和所有 Octave/MATLAB initialize/ending 函数都在主函数中,您的代码将是:

function test
  %%packages load below:

  %%initialization/ending functions here:
  clear -all; 
  clc;

  function nested1
     disp('nested 1')
  end

  function nested2
     disp('nested 2')
  end

   nested1
   nested2
end