MATLAB: How to collect the each row of a matrix after operation

color spaceimage processingImage Processing Toolboxmatrix manipulation

v=hsv(:,:,3);
p=1:256;
x=v(1:256, p);
h=imhist(v);
a=sum(x.*h);
b=sum(h);
M=a/b
the problem is that x should be of 256*1, and i want the vale of 'M' to be 256*256. which loop should i start so that p uses all value from 1 to 256 and automatically it should have its value in a form of a matrix of 256*256

Best Answer

What are you doing? It makes little sense to me. You're multiplying the histogram counts by the upper left 256x256 portion of the value channel image. Then you're summing the histogram to get b, which is simply the number of pixels in the image. Then you're dividing the "a" by "b". So essentially it looks like you're just computing the mean of the value channel, which can be done more simply as
M = mean2(v);