function [cx,cy]=findcline(x,y,xlim,tol) % FINDCLINE finds the point of highest gradient in columns of matrix % Made for finding the depth of the halo-/pycno-/thermocline etc. of % profiles. % % [cx,cy] = findcline(x,y,xlim,tol) % % x = position vector (or position-matrix) % y = corresponding vector or matrix for the data values % (columns=profiles). % x and y needs to be of same shape. % xlim = optional [min max] range of x in which to search for % the max gradient. % tol = tolerance for similar gradients in the neighbourhood of the % strongest, single value in % % % cx,cy = Coordinates of the ...cline, for each input profile. %Time-stamp: %File: error(nargchk(2,4,nargin)); if nargin<3 | isempty(xlim) | ~(isvec(xlim) & length(xlim)==2) xlim=mima(x); end if nargin<4 | isempty(tol), tol=10; end if issingle(x)|issingle(y), error('Vector- or matrix-input, please!');end if ismatrix(y) if ismatrix(x) & size(x)~=size(y) error('x and y needs to be of same size (corresponding values)!'); elseif isvec(x) [M,N]=size(y); if length(x)~=M error('x and y needs to be of same size (corresponding values)!'); else x=repmat(x(:),1,N); % build a position-matrix from x end end elseif isvec(y) if ismatrix(x), error('Can''t have position-MATRIX for a data-VECTOR!'); elseif length(x)~=length(y), error('Vectors must be of equal length!'); else y=y(:); x=x(:); end end %find(xlim(1)<=x(:,1) & x(:,1)<=xlim(2));% limit to given range %x=x(ans,:); y=y(ans,:); % x