Q:

Matlab storing values in array

I would like to read an image pixel by pixel and store how many of each pixel value there are (grayscale 0-255):
img = imread('jetplaneCor.jpg');
imgGray = rgb2gray(img);
sizex = size(imgGray,1);
sizey = size(imgGray,2);
grayArray = [0:0:255]; %Not working

for i=0:1:sizex
   for j=0:1:sizey
       pixelValue = imgGray(i,j);
       grayArray(pixelValue)=grayArray(pixelValue)+1;
   end
end

How can i allocate an array with 256 places?

A:

This will create a 1 x 256 array where every entry is a 0:
grayArray = zeroes(1, 256);

You can reference each element with:
grayArray(1, index);

