Home > NoiseTools > nt_peaksign.m

# nt_peaksign

## PURPOSE

sgn=peaksign(x,dim) - sign of largest extremum

## SYNOPSIS

function sgn=nt_peaksign(x,dim)

## DESCRIPTION

    sgn=peaksign(x,dim) - sign of largest extremum

     If dim is present, give array of signs along that dimension

## CROSS-REFERENCE INFORMATION

This function calls:

- nt_peaksign sgn=peaksign(x,dim) - sign of largest extremum

This function is called by:

- nt_peaksign sgn=peaksign(x,dim) - sign of largest extremum

## SOURCE CODE

    0001 function sgn=nt_peaksign(x,dim)
    0002 %sgn=peaksign(x,dim) - sign of largest extremum
    0003 %
    0004 % If dim is present, give array of signs along that dimension
    0005
    0006 if nargin<2; dim=[]; end
    0007
    0008 if isempty(dim)
    0009     if max(-x(:))>max(x(:));
    0010         sgn=-1;
    0011     else
    0012         sgn=1;
    0013     end
    0014 else
    0015     if dim>4; error('1'); end
    0016     [m,n,o,p]=size(x);
    0017     if dim==1
    0018         for k=1:m
    0019             sgn(k)=nt_peaksign(x(k,:,:,:));
    0020         end
    0021     elseif dim==2
    0022         for k=1:n
    0023             sgn(k)=nt_peaksign(x(:,k,:,:));
    0024         end
    0025     elseif dim==3
    0026         for k=1:o
    0027             sgn(k)=nt_peaksign(x(:,:,k,:));
    0028         end
    0029     else
    0030         for k=1:p
    0031             sgn(k)=nt_peaksign(x(:,:,:,k));
    0032         end
    0033     end
    0034 end
    0035