title: Error of Averaging a Large Vector in MATLAB
body: <p>How do you accurately take the average of large sets of integers in MATLAB?
  I have two large vectors (2672x4008 in dimensions) I am dealing with, each the result of pixels in an image. Hence, the resulting vector is filled with values 0 to 256, all integers. My problem is that I want an accurate value of the average intensity of these grey-scale images. To do this, I used the line</p>
  
  <pre><code>meanvalue = mean(I(:))
  </code></pre>
  
  <p>This yielded a value of meanvalue = 155.9335 in the output line of MATLAB.</p>
  
  <p>Next, I added 20 to each value of the vector, as below (this should raise the intensity of the overall image, if I am understanding correctly).</p>
  
  <pre><code>Ipt = I + 20;
  </code></pre>
  
  <p>I then took the mean value of this new vector, Ipt</p>
  
  <pre><code>meanvaluept = mean(Ipt(:))
  </code></pre>
  
  <p>and matlab spat out a value of meanvaluept = 175.8916. I'm no math wizard, but I know enough to know that 175.8916 - 20 ≠ 155.9335.</p>
  
  <p>Any help would be appreciated, either mathematically (how to increase the precision of MATLAB), or procedurally (there is some built-in function of MATLAB which will find the intensity).</p>