title: How to write a single Octave script with function definitions compatible with Matlab scripts?
body: <p>If I write this:</p>
  
  <pre class="lang-matlab prettyprint-override"><code>clc
  clear
  
  close all
  format long
  fprintf( 1, 'Starting...\n' )
  
  function results = do_thing()
      results = 1;
  end
  
  results = do_thing()
  </code></pre>
  
  <p>And run it with <code>Octave</code>, it works correctly:</p>
  
  <pre><code>Starting...
  results =  1
  </code></pre>
  
  <p>But if I try to run it with <code>Matlab 2017b</code>, it throws this error:</p>
  
  <pre><code>Error: File: testfile.m Line: 13 Column: 1
  Function definitions in a script must appear at the end of the file.
  Move all statements after the "do_thing" function definition to before the first local function
  definition.
  </code></pre>
  
  <p>Then, if I fix the error as follows: </p>
  
  <pre class="lang-matlab prettyprint-override"><code>clc
  clear
  
  close all
  format long
  fprintf( 1, 'Starting...\n' )
  
  results = do_thing()
  
  function results = do_thing()
      results = 1;
  end
  </code></pre>
  
  <p>It works correctly on <code>Matlab</code>:</p>
  
  <pre><code>Starting...
  
  results =
  
       1
  </code></pre>
  
  <p>But now, it stopped working with <code>Octave</code>:</p>
  
  <pre><code>Starting...
  error: 'do_thing' undefined near line 8 column 11
  error: called from
      testfile at line 8 column 9
  </code></pre>
  
  <p>This problem was explained on this question: <a href="https://stackoverflow.com/questions/54013267/run-octave-script-file-containing-a-function-definition">Run octave script file containing a function definition</a></p>
  
  <p>How to fix it without having to create a separate and exclusive file for the function <code>do_thing()</code>?</p>
  
  <p>Is this issue fixed on some newer version of <code>Matlab</code> as <code>2019a</code>?</p>