# VMT_LayerAveMean

## PURPOSE

Computes the layer averaged mean of y over the depth range.

## SYNOPSIS

function lam = VMT_LayerAveMean(x,y)

## DESCRIPTION

     Computes the layer averaged mean of y over the depth range.
     Assumes the data outside the depth range have been set to NaN.

     P.R. Jackson, USGS 1-7-09

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- VMT_PlotPlanViewQuivers This function plots a plan view of the measurement region with a vector

## SOURCE CODE

    0001 function lam = VMT_LayerAveMean(x,y)
    0002 % Computes the layer averaged mean of y over the depth range.
    0003 % Assumes the data outside the depth range have been set to NaN.
    0004 %
    0005 % P.R. Jackson, USGS 1-7-09
    0006
    0007 % Preallocate
    0008 intgrl = nan*ones(1,size(y,2));
    0009 dz = nan*ones(1,size(y,2));
    0010
    0011 for i = 1:size(y,2)
    0012     indx        = find(~isnan(y(:,i)));
    0013     if isempty(indx)
    0014         intgrl(i) = NaN;
    0015         dz(i)     = NaN;
    0016     elseif length(indx) == 1;  %Allows a single value mean: mean value = single value (nan before) %PRJ, 3-11-11
    0017         intgrl(i) = y(indx,i);
    0018         dz(i)     = 1;
    0019     elseif length(indx) > 1;
    0020         xt          = x(indx,i);
    0021         yt          = y(indx,i);
    0022         intgrl(i)   = trapz(xt,yt,1);
    0023         dz(i)       = nanmax(xt) - nanmin(xt);
    0024     end
    0025     clear indx
    0026 end
    0027 lam = intgrl./dz;
    0028
    0029