I have got this matlab code ,every time i try to run it an error saying that the

??? Input argument "state" is undefined.

Error in ==> pd_controlleraa at 9
if ~isfield(state, 'integral')


kindly help me to debug this problem

this is the code of matlab

% Compute system inputs and updated state.
% Note that input = [$\gamma_1$, $\ldots$, $\gamma_4$]
function [input, state] = pd_controlleraa(state, thetadot)
% Controller gains, tuned by hand and intuition.
Kd = 4;
Kp = 3;

% Initialize the integral if necessary.
if ~isfield(state, 'integral')
params.integral = zeros(3, 1);
end

% Compute total thrust
total = state.m * state.g / state.k / (cos(state.integral(1)) * cos(state.integral(2)));

% Compute errors
e = Kd * thetadot + Kp * params.integral;

% Solve for the inputs, $\gamma_i$
input = error2inputs(params, accels, total);

% Update the state
params.integral = params.integral + params.dt .* thetadot;
end