load abalone.csv -ascii;

A = abalone;
clear abalone
m = size(A,2);

for i = 1:m
    idx = find(A(:,i) < 0);
    switch i
        case 1
            h = -1:2;
            p = histc(A(:,i),h);
            % histogram plot  hist(A(:,i),h);           
            [foo,j] = max(p(2:end));    %[max value, max value position]
            A(idx,i) = h(j + 1);        % set to max value            
        case {2,3,4,5,6,7,8}
            % first mean, second zscore
            A(idx,i) = posmean(A(:,i));
            A(:,i)   = zscore(A(:,i));
        otherwise
            A(idx,i) = posmedian(A(:,i));
    end
end
%A
%mean(A(:,2))
% without any loop is possible if posmean is implemented 
% as follows: given a matrix A, posmean returns a row 
% vector with posmean of each column.
%
% i = find(A == -1); 
% a = posmean(A);
% A(i) = a(floor(1 + (i-1)/size(A,1)));
