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: findpaths.m
    path of file: ./repos/CanlabCore/CanlabCore/External/2019_03_03_BCT
    
    the code of the file until where you have to start completion: function [Pq,tpath,plq,qstop,allpths,util] = findpaths(CIJ,sources,qmax,savepths)
%FINDPATHS      Network paths
%
%   [Pq,tpath,plq,qstop,allpths,util] = findpaths(CIJ,sources,qmax,savepths);
%
%   Paths are sequences of linked nodes, that never visit a single node
%   more than once. This function finds all paths that start at a set of 
%   source nodes, up to a specified length. Warning: very memory-intensive.
%
%   Inputs:     CIJ,        binary (directed/undirected) connection matrix
%               qmax,       maximal path length
%               sources,    source units from which paths are grown
%               savepths,   set to 1 if all paths are to be collected in
%                           'allpths'
%
%   Outputs:    Pq,         3D matrix, with P(i,j,q) = number of paths from
%                           'i' to 'j' of length 'q'.
%               tpath,      total number of paths found (lengths 1 to 'qmax')
%               plq,        path length distribution as a function of 'q'
%               qstop,      path length at which 'findpaths' is stopped
%               allpths,    a matrix containing all paths up to 'qmax'
%               util,       node use index
%
%   Note that Pq(:,:,N) can only carry entries on the diagonal, as all
%   "legal" paths of length N-1 must terminate.  Cycles of length N are
%   possible, with all vertices visited exactly once (except for source and
%   target). 'qmax = N' can wreak havoc (due to memory problems).
%
%   Note: Weights are discarded.
%   Note: I am certain that this algorithm is rather inefficient -
%   suggestions for improvements are welcome.
%
%   Olaf Sporns, Indiana University, 2002/2007/2008/2010

%   2010 version:
%   -- a bug affecting the calculation of 'util' was fixed -- thanks to
%      Steve Williams
%   -- better pre-allocation for 'npths'
%   -- note that this code assumes a directed graph as input - calculation
%      of paths and 'util' indices can be easily adapted to undirected
%      graphs. 

% ensure CIJ is binary...
CIJ = double(CIJ~=0);

% initialize some variables

    
function [Pq,tpath,plq,qstop,allpths,util] = findpaths(CIJ,sources,qmax,savepths)
%FINDPATHS      Network paths
%
%   [Pq,tpath,plq,qstop,allpths,util] = findpaths(CIJ,sources,qmax,savepths);
%
%   Paths are sequences of linked nodes, that never visit a single node
%   more than once. This function finds all paths that start at a set of 
%   source nodes, up to a specified length. Warning: very memory-intensive.
%
%   Inputs:     CIJ,        binary (directed/undirected) connection matrix
%               qmax,       maximal path length
%               sources,    source units from which paths are grown
%               savepths,   set to 1 if all paths are to be collected in
%                           'allpths'
%
%   Outputs:    Pq,         3D matrix, with P(i,j,q) = number of paths from
%                           'i' to 'j' of length 'q'.
%               tpath,      total number of paths found (lengths 1 to 'qmax')
%               plq,        path length distribution as a function of 'q'
%               qstop,      path length at which 'findpaths' is stopped
%               allpths,    a matrix containing all paths up to 'qmax'
%               util,       node use index
%
%   Note that Pq(:,:,N) can only carry entries on the diagonal, as all
%   "legal" paths of length N-1 must terminate.  Cycles of length N are
%   possible, with all vertices visited exactly once (except for source and
%   target). 'qmax = N' can wreak havoc (due to memory problems).
%
%   Note: Weights are discarded.
%   Note: I am certain that this algorithm is rather inefficient -
%   suggestions for improvements are welcome.
%
%   Olaf Sporns, Indiana University, 2002/2007/2008/2010

%   2010 version:
%   -- a bug affecting the calculation of 'util' was fixed -- thanks to
%      Steve Williams
%   -- better pre-allocation for 'npths'
%   -- note that this code assumes a directed graph as input - calculation
%      of paths and 'util' indices can be easily adapted to undirected
%      graphs. 

% ensure CIJ is binary...
CIJ = double(CIJ~=0);

% initialize some variables
N = size(CIJ,1); K = sum(sum(CIJ));
pths = [];
Pq = zeros(N,N,qmax);
util = zeros(N,qmax);

% this code is for pathlength = 1
% paths are seeded from 'sources'
q = 1;
for j=1:N
    for i=1:length(sources)
        is = sources(i);
        if (CIJ(is,j) == 1)
            pths = [pths [is j]'];
        end