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: shadem.m
    path of file: ./repos/CDT/cdt
    
    the code of the file until where you have to start completion: function [lighth,MaterialType,gain,LightingType,LightAngle] = shadem(varargin) 
% shadem applies relief shading or "hillshade" to a map. 
% 
% shadem adjusts lighting to give a sense of depth to the display of 
% gridded elevation data. Although it was designed for use with the Matlab's 
% Mapping Toolbox, this function can just as easily be used for pcolor or
% surface plots of any type and the Mapping Toolbox is not required.  
% 
% Matlab's Mapping Toolbox comes wit
    
function hs = shadecalc(dem,dx,az,el,gain)

zf = 2^gain; 
% zf is scaling factor.
% Convert azimuth and elevation to radians: 
az = az*pi/180+90; 
el = el*pi/180; 

% calc slope and aspect (radians)
[fx,fy] = gradient(dem,dx,dx); % simple, unweighted gradient of immediate neighbours
[asp,grad]=cart2pol(fy,fx); 

grad=atan(zf*grad); 
asp(asp<pi)=asp(asp<pi)+pi/2;
asp(asp<0)=asp(asp<0)+2*pi;

hs =  cos(el).*cos(grad) + sin(el).*sin(grad).*cos(az-asp) ; % ESRIs algorithm
hs(hs<0)=0; % set hillshade values to min of 0.


end