MATLAB: How to sum column of matrix

matrixmatrix manipulationsum

hello everyone, I want to sum the percentage of the first three columns from the A matrix acoording the matrix T, there is an exemple of matrix :
A=[1,3,15,598,58,15,25,4,9,10;
4,4,25,1,1,9,47,121,44,12;
10,11,47,3,5,7,98,15,55,888;
4,8,1,23,58,444,17,9,8,5;
7,25,14,89,547,3,10,11,15,47;
1,15,24,,1,5,947,5,48,7,12;
47,8,5,1,2,69,78,555,47,11 ];
T=[1;4;11;1;100;54;5]
I want to compare the first column of A with the matrix T and calculate the percentage that this column contains the same value than the matrix T. the next step is to compare the second column of A with T and add the percentage that this column contains some values missing compared to the first column. the final step is similar than later but using the third column.
for more explanation, here is a small example
a=[1,5,8,9;
4,4,7,1;
9,5,48,175;
5,48,4,2,1 ====>first-clm=[1,4,9,5,2] than pourcentage =40%

2,58,4,1,7] ====>second-clm=[5,4,5,48,58] than pourcentage =20% =========> the final pourcentage is 80%
t=[1,4,5,4,11] ====>third-clm=[8,7,48,4,4] than pourcentage =20%
please help me, How can do this in matlab?

Best Answer

idx = bsxfun( @eq, a, t' );
percent = 100 * sum( any( idx, 2 ) ) / numel( t );
would work for your second example. In the first example your T is a column vector rather than a row vector so you would want to remove the transpose from the first line - i.e.
idx = bsxfun( @eq, A, T );
should work there.