MATLAB: How to create a variable changing with index number

digital image processingImage Processing Toolbox

how can I create a variable N such that it's value changing with the index and then do the summation, i.e:
∑_Ni from i=0 to i=255 ,
where Ni is the number of pixels that have intensity value Ri
For knowledge, I have an image with its histogram.

Best Answer

You can do
i = 0:255;
though you don't need to do that to take the sum. To sum the histogram of the image you can do
[pixelCounts, grayLevels] = imhist(grayscaleImage);
theSum = sum(pixelCounts(:));