function [xc, xm, xsd] = normalize2(x,str,fin)
%Normalize2  Normalize data by subtraction of the mean and scaling of st. dev
%            over a calibration period (rows) [str:fin] 
%
%    [XC, XM, XSD] = NORMALIZE(X,STR,FIN) normalizes the data in X by subtraction 
%    of the mean XM over XM(STR:FIN,:) and scaling by XSD. If X contains NaNs, 
%    indicating missing values, the mean of X is computed from the available data.
%
%    See also NANMEAN, MEAN, CENTER.

%  error(nargchk(1,1,nargin))          % check number of input arguments 
  if ndims(x) > 2,  error('X must be vector or 2-D array.'); end
  
  % if x is a vector, make sure it is a row vector
  if length(x)==prod(size(x))         
    x   = x(:);                         
  end 
  [m,n] = size(x);

  str=max(0,str);
  fin=min(m,fin);

  % get mean, sdev of x over interval
  xm  = nanmean(x(str:fin,:));
  xsd = nanstd(x(str:fin,:));	

  % remove mean and scale
  xc    = (x - repmat(xm,m,1))./repmat(xsd,m,1);


