function F = lmaxcdf3vec(x,l,w,gbar,Etaext,Rext)
C = length(x);
R = length(Etaext(2:end-1));
Etamat = repmat(Etaext(2:end-1)',1,C);
Rmat = repmat(Rext(2:end-1)',1,C);
s_l = repmat(l/w*((Etaext(2:end-1)-Etaext(1:end-2))./(Rext(2:end-1)-Rext(1:end-2)))',1,C);
s_u = repmat(l/w*((Etaext(3:end)-Etaext(2:end-1))./(Rext(3:end)-Rext(2:end-1)))',1,C);
% Plstar = expcdf(s_u,gbar)-expcdf(s_l,gbar);
fg = l*Etamat./max(w*Rmat-X,0);
fg(isnan(fg)) = inf;
F = sum(max((expcdf(min(fg,s_u),gbar)-expcdf(s_l,gbar)),0));
end