title: How to define a matrix valued function in Matlab/Octave -- return value syntax
body: <p>I'm trying to verify some matrix rotation calculations, and thought it would be easiest to drop into Octave (Matlab) and define a simple function to do this.  But I am stymied by some syntax difficulties that I think are due to returning a matrix (multiple values).</p>
  
  <p>Ideally, I'd like to be able to key in something simple, where I can choose the rotation degree and the point to be rotated, for example:</p>
  
  <pre><code>rot(45)*[1 0]'  % rotate unit vector by 45 degrees
  </code></pre>
  
  <p>I'd expect to get back the correct answer:  <code>0.70711  0.70711</code></p>
  
  <p>However, this means that rot(45) must return a matrix in a form that can then be multiplied immediately by the vector.</p>
  
  <p>To do this I've defined the following function, using the [ R ] syntax to indicate multiple return values:</p>
  
  <pre><code> function [ R ] = rot(th_deg)
      [ cos(th_deg * pi/180)  -sin(th_deg * pi/180) ;
        sin(th_deg) * pi/180)  cos(th_deg * pi/180)   ]
   end
  </code></pre>
  
  <p>Calling function <code>rot(45)</code> by itself works fine and shows the correct 2x2 rotation matrix.</p>
  
  <p>But trying to use this rotation matrix returned value in the further multiplication yields the warning message: <code>warning: some elements in list of return values are undefined</code></p>
  
  <p>Any idea what's going wrong?</p>
  
  <p>Thanks,</p>