title: How to write MATLAB functions in Jupyter Notebook?
body: <h2>Overview</h2>
  
  <p>I am using the <a href="https://pypi.python.org/pypi/matlab_kernel" rel="noreferrer">MATLAB kernel</a> in Jupyter Notebook. I would like to write a function in the notebook, rather than referring to a function that is saved in another <code>.m</code> file. The problem is that when I try to do so, I get the error:</p>
  
  <blockquote>
    <p>Error: Function definitions are not permitted in this context.</p>
  </blockquote>
  
  <h2>Visual example:</h2>
  
  <p>In a new notebook, it looks like the following picture:</p>
  
  <p><a href="https://i.stack.imgur.com/GSJ8M.png" rel="noreferrer"><img src="https://i.stack.imgur.com/GSJ8M.png" alt="enter image description here"></a></p>
  
  <p>Now, it does work if I make a new <code>.m</code> file:</p>
  
  <p><a href="https://i.stack.imgur.com/fSjSd.png" rel="noreferrer"><img src="https://i.stack.imgur.com/fSjSd.png" alt="enter image description here"></a></p>
  
  <p>and then call then function via the notebook:</p>
  
  <p><a href="https://i.stack.imgur.com/9Thtd.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9Thtd.png" alt="enter image description here"></a></p>
  
  <p>but this is inconvenient. Is there a way to define functions from within a Jupyter Notebook directly?</p>
  
  <h2>My software</h2>
  
  <ul>
  <li>MATLAB 2017b</li>
  <li>Windows 10</li>
  <li>Jupyter running in chrome</li>
  <li>Jupyter installed via anaconda</li>
  </ul>