title: Matlab anonymous function with array inputs
body: <p>I have an anonymous function:</p>
  
  <pre><code>a = [1, 2];
  b = [1, 1; 3, 2];
  c = [4, 2];
  ff = @(x) (exp(a .* x) .* c) * b;
  </code></pre>
  
  <p>The problem is that, when I have an array, say <code>x = [1,2,3,4]</code> , Matlab thinks that I'm using the array and multiplying that in the exponential, and not each element.
  The error is</p>
  
  <blockquote>
    <p>Error using  .* 
    Matrix dimensions must agree.</p>
    
    <p>Error in
    @(x)(exp(a.*x).*c)*b</p>
  </blockquote>
  
  <p>I just need something like  <code>c1 * exp(a1 *x) * b11 + c2 * exp(a2 * x) * b21 + ...</code> </p>
  
  <p>I can use a <code>for</code> loop if I want to evaluate the function for each <code>x</code> element and it gives me the answer that I want, but I think there may be an easiest way, like when we can use simply <code>f(x)</code> and get an array with each element evaluated in the function. I tried using <code>arrayfun</code> but I get the same error. I want to skip <code>for</code> loops since they are slow for bigger matrices.</p>