title: Alternative to diag(X'*C*X) in matlab
body: <p>Consider an N x 1 vector x and an N x N matrix C. I would like to evaluate</p>
  
  <pre><code> s = x'*C*x;
  </code></pre>
  
  <p>in matlab for many sampled of the vector x, e.g. consider M samples of x as an N x M matrix X; this can be done using </p>
  
  <pre><code>S = diag(X'*C*X);
  </code></pre>
  
  <p>but this is a poor solution as an M x M matrix is allocated in the process, and this breaks for M>1e5. Is there some matlab functionality which can suggest an alternative?</p>