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: sparsify.m
    path of file: ./repos/Image-Harmonization-Dataset-iHarmony4/Lalonde and Efros/colorStatistics/3rd_party/segmentationBerkeley/CSA++
    
    the code of the file until where you have to start completion: function graph = sparsify(sm)
% function graph = sparsify(sm)
%
% Given a smilarity matrix sm, return a sparse graph representation
% suitable for csaAssign.  For example, if sm is an nxn similarity

    
function graph = sparsify(sm)
% function graph = sparsify(sm)
%
% Given a smilarity matrix sm, return a sparse graph representation
% suitable for csaAssign.  For example, if sm is an nxn similarity
% matrix, then Hungarian-style matching can be accomplished by
% executing csaAssign(2*n,sparsify(sm)).
%
% See also csaAssign.
%
% David Martin <dmartin@eecs.berkeley.edu>
% March, 2003

if ndims(sm)~=2 | size(sm,1)~=size(sm,2),
  error('sm must be a square matrix');
end