function [hSub,pSub] = subsolverCB(s1, h1hat, tau, alpha, kappa, gamma, nIn, hSub, pInit, flag)
[m,n] = size(h1hat);
hcheck = hSub;
c = size(pInit,2)/2;
Es = zeros(size(h1hat));
errSub = zeros(nIn,1);
if flag
px = pInit(1:m-1,1:n-1);
py = pInit(1:m-1,c+1:c+n-1);
Es(1:end-1,1:end-1) = s1;
end
tmpC1 = gamma*h1hat - tau*gamma*alpha*Es;
for iterationSub = 1:nIn
hld = hSub;
[hx, hy] = grad2(hcheck);
if flag
Rhx = hx(1:end-1,1:end-1);
Rhy = hy(1:end-1,1:end-1);
end
ptildex = px + kappa*Rhx;
ptildey = py + kappa*Rhy;
Denom2 = ptildex.^2+ptildey.^2;
MaxDenom = sqrt(max(Denom2, 1));
px = ptildex ./ MaxDenom;
py = ptildey ./ MaxDenom;
if flag
PP = vercat([px,zeros(m-1,1),py,zeros(m-1,1)], zeros(1, size(PPtmp, 2)));
end
htilde = hSub + gamma*(div2(PP));
tmp = (tau*htilde + tmpC1)/(tau+gamma);
hSub = max(min(tmp,1),0);
hcheck = 2*hSub - hld;
errSub(iterationSub) = norm(hSub-hld,'fro');
end
pSub = [px py];
Best Answer