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: bnet_to_fgraph.m
    path of file: ./repos/bnt/BNT/general
    
    the code of the file until where you have to start completion: function fg = bnet_to_fgraph(bnet)
% BNET_TO_FGRAPH Convert a Bayes net to a factor graph
% fg = bnet_to_fgraph(bnet)
%
% We create one factor per family, whose kernel is the CPD


    
function fg = bnet_to_fgraph(bnet)
% BNET_TO_FGRAPH Convert a Bayes net to a factor graph
% fg = bnet_to_fgraph(bnet)
%
% We create one factor per family, whose kernel is the CPD

nnodes = length(bnet.dag);
G = zeros(nnodes, nnodes);
for i=1:nnodes
  G(family(bnet.dag, i), i) = 1;
end