%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [X_p, Mx_cal, Sx_cal]=scal2D(X,pret,Mx_cal,Sx_cal)


    %%% centering
    dimX=size(X);
    if pret(1,:)=='mnc'
        if isempty(Mx_cal)==1
            Mx_cal = missmean(X);
        end
        X_p = X-ones(dimX(1),1)*Mx_cal;
    else
        X_p=X;
    end
    %%%%% scaling
    if pret(2,:)=='aut'
        if isempty(Sx_cal)==1
            Sx_cal=missstd(X);
        end
        X_p=X_p./(ones(dimX(1),1)*Sx_cal);
    end
    if pret(2,:)=='psc'
        if isempty(Sx_cal)==1
            Sx_cal=sqrt(missstd(X));
        end
        X_p=X_p./(ones(dimX(1),1)*Sx_cal);
    end
%%%%%%            
%%%%%%
