You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: local_documentation.m
    path of file: ./repos/CDT/cdt/doc
    
    the code of the file until where you have to start completion: %% |local| documentation 
% The |local| function returns a 1D array of values calculated fro
    
function returns a 1D array of values calculated from a region of interest in a 3D matrix. 
% For example, if you have a big global 3D sea surface temperature dataset, this function
% makes it easy to obtain a time series of the average sst within a region of interest. 
% 
% <CDT_Contents.html Back to Climate Data Tools Contents>
%% Syntax 
% 
%  y = local(A)
%  y = local(A,mask)
%  y = local(A,mask,'weight',weight)
%  y = local(A,mask,@function) 
%  y = local(...,FunctionInputs,...)
%  y = local(...,'omitnan')
% 
%% Description 
% 
% |y = local(A)| produces a time series or profile from the mean values of each 2D 
% slice along dimension 3 of the 3D matrix |A|. 
% 
% |y = local(A,mask)| gives a time series values within a region of interest defined by |mask| inside a 
% a big gridded time series matrix |A|. For matrix |A| of dimensions MxNxP, the dimensions of
% |mask| must be MxN and the dimensions of output |y| are Px1.
%  
% |y = local(...,'weight',weight)| weights averages by any given weighting grid such as that produced by <cdtarea_documentation.html |cdtarea|>
% if you want an area-weighted mean. 
% 
% |y = local(A,mask,@function)| applies any function to the data values which make up each element
% of |y|. The default function is |@mean|, but you may use |@max|, |@std|, or just about
% any other function you can think of. You can even define your own <https://www.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html 
% anonymous function>. 
%  
% |y = local(...,FunctionInputs,...)| allows extra inputs to the specified function. For 
% example, the |std| function allows the standard deviation weighting scheme to be 
% either |0| or |1|; to specify the former, use |y = local(A,mask,@std,0)|. 
% 
% |y = local(...,'omitnan')| ignores |NaN| values.  
%  
%% Examples
% Load this sample data and for context, plot the mean sea surface temperature: 
 
load pacific_sst.mat

imagescn(lon,lat,mean(sst,3))
axis xy image
cmocean thermal 

xlabel 'longitude'
ylabel 'latitude'

%% Define a mask
% Some folks characterize ENSO by the mean sea surface temperature within
% the Nino 3.4 box, defined by the region between 5 N to 5 S latitude and 170 W to
% 120 W longitude. Let's get a time series of average sea surface
% temperatures within that box. Start by creating a mask corresponding to
% the Nino 3.4 box: 

% Turn lat and lon into grids: 
[Lon,Lat] = meshgrid(lon,lat); 

% Make a mask of ones inside the polygon: 
mask = geomask(Lat,Lon,[-5 5],[-170 -120]); 

figure
imagescn(lon,lat,mask)
axis xy tight

title 'Nino 3.4 mask'
xlabel 'longitude'
ylabel 'latitude'

ax = axis;
borders('countries')
axis(ax)

%% 
% That yellow rectangle contains the grid cells over which we'll calculate
% the mean SST time series. To get a time series of mean SST within the Nino
% 3.4 box, just give the |local| function, the |sst| dataset and the |mask|: 

y = local(sst,mask); 

figure
plot(t,y) 
axis tight
box off
datetick('x','keeplimits') 
ylabel(' sea surface temperature (\circC) ')

%% Area averaged mean 
% Assuming you are not in the Flat Earth Society, we'll have to deal with
% the inconvenient truth that the grid cells of latitude and longitude are
% not equal in area. If you want an area-weighted mean, use the
% <cdtarea_documentation.html |cdtarea|> function to get the area of the
% grid cells and use those areas as weights when calling |local|: 

Area = cdtarea(Lat,Lon); 

yw = local(sst,mask,'weight',Area); 

hold on
plot(t,yw)

%% 
% Now you might have noticed, the area-averaged values are *very* close to
% the unweighted means. That's because the Nino 3.4 box is close to the
% equator, where all the grid cells are about the same size. The largest 
% and smallest grid cells within the Nino 3.4 box only differ by about 0.2%
% in area, so calculating the area-weighted mean here is probably
% unnecessary. 
% 
% Want to see for yourself? Try the example above using the full |sst| dataset, 
% letting |mask = isfinite(mean(sst,3));|. Then you will see there's a big 
% difference between averages when the dimensions of the grid cells are taken
% into account. 

%% Beyond average 
% Maybe you don't want the average value within the Nino 3.4 box--maybe instead you need the maximum and minimum values. 
% Let's calculate the maximum and minimum values within the Nino 3.4 box as a function of time. Also get 
% the standard deviation and plot with <boundedline_documentation.html |boundedline|>: 

% Calculate max and min values within the Nino 3.4 box: 
ymax = local(sst,mask,@max); 
ymin = local(sst,mask,@min); 
ystd = local(sst,mask,@std); 

figure
boundedline(t,y,ystd); 

hold on
plot(t,ymin,':','color',rgb('gray'))
plot(t,ymax,':','color',rgb('gray'))

% Zoom in to see what's going on: 
ylim([22 31]) 
xlim([datenum('jan 1, 1990') datenum('jan 1, 2000')]) 
datetick('x','keeplimits') 

legend