title: MATLAB script code and function code in the same file?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5363397/in-matlab-can-i-have-a-script-and-a-function-definition-in-the-same-file">In MATLAB, can I have a script and a function definition in the same file?</a>  </p>
  </blockquote>
  
  
  
  <p>Can I have MATLAB script code and function code in the same file?</p>
  
  <pre><code>%% SAVED IN FILE myfunc.m (otherwise fail)
  function [out1] = myfunc( x )
  out1 = sqrt( 1 + (cos(x))^2 );
  end
  
  %%
  %OTHER CRAP
  y = 1:10
  % use myfunc
  </code></pre>
  
  <p>It doesn't seem to work, even with the <code>end</code> keyword there.  Is this type of thing allowed or do I always need to have EACH function in its own properly named file?</p>
  
  <p>I'm sure I saw functions and code that uses those functions in the same file a couple years ago.</p>