MATLAB: Compute probability of each element in each column of a m x n matrix.

histhistchistogramprobabilityprobability of each elementprobability of each element in each column of a matrix

Hello Friends,
I have a m x n matrix. I want to compute the probability of each element occurring in a column. I want to do it for each column.
For instance, suppose we have a 3 x 4 matrix:
A = [1 1 3 2; 2 3 0 2; 3 1 0 2];
Then, I would like to have the following matrix of probabilities: _P(A) = [ 1/3 2/3 1/3 1; 1/3 1/3 2/3 1; 1/3 2/3 2/3 1];_
Here, entries in P(A) are the probabilities of each element within the column.
For the 1st column: p(1) = p(2) = p(3) = 1/3
For the 2nd column: p(1) = 2/3, p(3) = 1/3
For the 3rd column: p(3) = 1/3, p(0) = 2/3
For the 4th column: p(2) = 3/3 = 1.
Please advise.

Best Answer

I found the solution of my own problem posted above. Though, thanks for your kind help. I will still appreciate different ways to solve it specially with hist(), and histc(). Here is my solution to this problem:
[r, c] = size(A);
y = zeros(r,c);
p = zeros(r,c);
for i = 1:c %Looping through the column.
for j = 1:r %Looping through the row in that that column.
y(j,i) = sum(A(:,[i]) == A(j,i)); %Compare each column of the matrix with the entries in that column.
p(j,i) = y(j,i)/r; %Probability of each entry of a column within that column.
end
end