Search code examples
matlaboctave

Octave nested functions "not implemented" error


My octave constantly reports me error:

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

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

as a reaction to following code (file named test.m):

clear -all;
clc;

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

  function nested2
    disp('nested2')
  end

  nested1()
  nested2()
end

I just don't get it. What's wrong?


Solution

  • Well, actual problem was that I had this code written in script file. What I really had to do is to turn it into function file.

    So. Buggy code looks like this:

    clear -all; 
    clc;
    
    function test
      function nested1
         disp('nested 1')
      end
    
      function nested2
         disp('nested 2')
      end
    
       nested1
       nested2
    end
    

    and working one is

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