MATLAB: HOW TO TAKE AVERAGE OF ROW AND COLUMN AT SOME POINT

average row column

I HAVE A MATRIX
2 5 3 500 4 5,
3 4 2 2 3 5,
4 5 5 1 2 2
code must scan first where 500 exists and take average of that row and column wher 500 exists excluding that 500,
here ans should be like avg row at first 2+5+3+4+5/5 and avg col of that point 2+1/2,

Best Answer

This works:
M = [2 5 3 500 4 5
3 4 2 2 3 5
4 5 5 1 2 2];
[r,c] = find(M == 500);
RowAvg = mean(M(r,M(r,:)~=500));
ColAvg = mean(M(M(:,c)~=500,c));