title: Updating one field in every element of a Matlab struct array
body: <p>Suppose I have a struct array <code>arr</code>, where each element has a bunch of fields, including one called <code>val</code>. I'd like to increment each element's <code>val</code> field by some constant amount, like so:</p>
  
  <pre><code>for i = 1:length(arr)
      arr(i).val = arr(i).val + 3;
  end
  </code></pre>
  
  <p>This obviously works, but I feel there should be a way to do this in just one line of code (and no for loop). The best I've come up with is two lines and requires a temp variable:</p>
  
  <pre><code>newVals = num2cell([arr.val] + 3);
  [arr.val] = deal(newVals{:});
  </code></pre>
  
  <p>Any ideas? Thanks.</p>