i tried this equation but it isn't working
for i=1:3
read=getsaample(ai)
Vmeasured=read(:,1)
e(i+1)= Vmeasured*2-Vref
IE=sum(e); %Integral of Error
%e= 18 - Vref
dt=.01
KP=2;
KI =1;
Int(i+1) = (e(i+1) + e(i))*dt/2; % integration of the error
I(i+1) = sum(Int); % the sum of the integration of the error
u=(KP*(e(i+1))+KI*I(i+1)) % control signal
end