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: grainMean.m
    path of file: ./repos/mtex/EBSDAnalysis/@EBSD
    
    the code of the file until where you have to start completion: function meanProp = grainMean(ebsd, prop, varargin)
% grain average property from ebsd properties

    
function meanProp = grainMean(ebsd, prop, varargin)
% grain average property from ebsd properties
%
% Syntax
%
%   % recover grains and store grainId 
%   [grains,ebsd.grainId] = calcGrains(ebsd)
%
%   % compute average grain property
%   meanPropG = grainMean(ebsd, ebsd.ci, grains);
%   plot(grains,meanPropG)
%
%   % compute average grain property for each EBSD pixel
%   meanPropE = grainMean(ebsd, ebsd.ci, grains);
%   plot(ebsd,meanPropE)
%
%   % take not the mean but the maximum per grain
%   meanPropG = grainMean(ebsd, ebsd.ci, grains, @max);
%   plot(grains,meanPropG)
%
% Input
%  ebsd   - @EBSD (which must contain a grainId)
%  prop   - property to average, same size as ebsd
%  grains - @grain2d
%  method - function_handle
%
% Output
%  meanPropG - average property, sorted as grains
%  meanPropE - average property, sorted as EBSD
%
% Options
%  ulim   - upper limit to consider (upper limit)
%  llim   - lower limit to consider (lower limit)
%

% check for grainId
if isempty(ebsd.grainId)
  error('There is no ebsd.grainId. Run calcGrains first.')
end