title: How to implement a part of histogram equalization in matlab without using for loops and influencing speed and performance
body: <p>Suppose that I have these Three variables in matlab  <a href="http://www.4shared.com/rar/xUDqy8up/variables.html" rel="nofollow">Variables</a><br>
  I want to extract diverse values in NewGrayLevels and sum rows of OldHistogram that are in the same rows as one diverse value is.<br>
  For example you see in NewGrayLevels that the six first rows are equal to zero. It means that 0 in the NewGrayLevels has taken its value from (0 1 2 3 4 5) of OldGrayLevels. So the corresponding rows in OldHistogram should be summed.<br>
  So 0+2+12+38+113+163=328 would be the frequency of the gray level 0 in the equalized histogram and so on.<br>
  Those who are familiar with image processing know that it's part of the histogram equalization algorithm.<br>
  Note that I don't want to use built-in function "histeq" available in image processing toolbox and I want to implement it myself.<br>
  I know how to write the algorithm with for loops. I'm seeking if there is a faster way without using for loops.<br>
  The code using for loops:  </p>
  
  <pre><code>   for k=0:255
         Condition = NewGrayLevels==k;
         ConditionMultiplied = Condition.*OldHistogram;
         NewHistogram(k+1,1) = sum(ConditionMultiplied);
     end  
  </code></pre>
  
  <p>I'm afraid if this code gets slow for high resolution big images.Because the variables that I have uploaded are for a small image downloaded from the internet but my code may be used for sattellite images. </p>