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: update_ess4.m
    path of file: ./repos/bnt/BNT/CPDs/@hhmmQ_CPD/Old
    
    the code of the file until where you have to start completion: function CPD = update_ess(CPD, fmarginal, evidence, ns, cnodes, hidden_bitv)
% UPDATE_ESS Update the Expected Sufficient Statistics of a hhmm Q node.
% function CPD = update_ess(CPD, fmarginal, evidence, ns, cnodes, idden_bitv)
%
% we assume if one of the Qps is observed, all of them are 
% We assume the F nodes are already hidden 


    
function CPD = update_ess(CPD, fmarginal, evidence, ns, cnodes, hidden_bitv)
% UPDATE_ESS Update the Expected Sufficient Statistics of a hhmm Q node.
% function CPD = update_ess(CPD, fmarginal, evidence, ns, cnodes, idden_bitv)
%
% we assume if one of the Qps is observed, all of them are 
% We assume the F nodes are already hidden 

% Figure out the node numbers associated with each parent
dom = fmarginal.domain;
self = dom(CPD.self_ndx);
old_self = dom(CPD.old_self_ndx);
%Fself = dom(CPD.Fself_ndx);
%Fbelow = dom(CPD.Fbelow_ndx);
Qps = dom(CPD.Qps_ndx);

Qsz = CPD.Qsz;
Qpsz = CPD.Qpsz;


% hor_counts(old_self, Qps, self),
% fmarginal(old_self, Fbelow, Fself, Qps, self)
% hor_counts(i,k,j) = fmarginal(i,2,1,k,j) % below has finished, self has not
% ver_counts(i,k,j) = fmarginal(i,2,2,k,j) % below has finished, and so has self (reset)
% Since any of i,j,k may be observed, we write
% hor_counts(i_counts_ndx, kndx, jndx) = fmarginal(i_fmarg_ndx...)
% where i_fmarg_ndx = 1 and i_counts_ndx = i if old_self is observed to have value i,
% i_fmarg_ndx = 1:Qsz and i_counts_ndx = 1:Qsz if old_self is hidden, etc.


if hidden_bitv(old_self)
  i_counts_ndx = 1:Qsz;
  i_fmarg_ndx = 1:Qsz;
  eff_oldQsz = Qsz;
else
  i_counts_ndx = evidence{old_self};
  i_fmarg_ndx = 1;
  eff_oldQsz = 1;
end