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: KAM.m
    path of file: ./repos/mtex/EBSDAnalysis/@EBSDhex
    
    the code of the file until where you have to start completion: function kam = KAM(ebsd,varargin)
% intragranular average misorientation angle per orientation
%
% Syntax
%
%   plot(ebsd, ebsd.KAM ./ degree)
%
%   % ignore misorientation angles > threshold
%   kam = KAM(ebsd, 'threshold', 10*degree);
%   plot(ebsd,kam./degree)
%
%   % ignore grain boundary misorientations
%   [grains, ebsd.grainId] = calcGrains(ebsd)
%   plot(ebsd, ebsd.KAM./degree)
%
%   % consider also second order neigbors
%   kam = KAM(ebsd, 'order', 2);
%   plot(ebsd, kam./degree)
%
% Input
%  ebsd - @EBSDhex
%
% Options
%  threshold - ignore misorientation angles larger then threshold
%  order     - consider neighbors of order n

    
function kam = KAM(ebsd,varargin)
% intragranular average misorientation angle per orientation
%
% Syntax
%
%   plot(ebsd, ebsd.KAM ./ degree)
%
%   % ignore misorientation angles > threshold
%   kam = KAM(ebsd, 'threshold', 10*degree);
%   plot(ebsd,kam./degree)
%
%   % ignore grain boundary misorientations
%   [grains, ebsd.grainId] = calcGrains(ebsd)
%   plot(ebsd, ebsd.KAM./degree)
%
%   % consider also second order neigbors
%   kam = KAM(ebsd, 'order', 2);
%   plot(ebsd, kam./degree)
%
% Input
%  ebsd - @EBSDhex
%
% Options
%  threshold - ignore misorientation angles larger then threshold
%  order     - consider neighbors of order n
%  max       - take not the mean but the maximum misorientation angle
%
% See also
% grain2d.GOS

% ensure that we have not to deal with symmetry anymore
if isfield(ebsd.prop,'grainId'), ebsd = ebsd.project2FundamentalRegion; end