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: find_components.m
    path of file: ./repos/SuiteSparse/MATLAB_Tools/find_components
    
    the code of the file until where you have to start completion: function [p, r, nc, G, xy] = find_components (A,sorted)
%FIND_COMPONENTS finds all connected components of an image.
% Two pixels in an image are in the same connected component if and only if
% they are adjacent and have the same value.  "Adjacent" in this context means
% north/south or east/west, not diagonally.  That is, A(2,3) is adjacent to
% A(2,2), A(2,4), A(1,3), and A(3,3) only, and is not adjacent to A(3,4).
%
% Let [p r] = find_components(A) where A is m-by-n.  The result is a permutation
% p and component boundaries r.  p is a permutation of 1:m*n, and refers to the
% linear indexing of A.  That is, A(i,j) is refered to as A(i+j*m) in the list
% p.  The kth connected component consists of A (p (r(k) : r(k+1)-1)).
% The number of connected components is nc = length (r) - 1.  The components
% are ordered by the smallest linear index in each component (assuming you have
% MATLAB 7.5 or later, which uses DMPERM from CSparse; otherwise the ordering
% is not defined).
%
% With a single output argument, c = find_components (A) just returns a list
% of the nodes in the largest component (the component with the largest value
% if ties, and if there are 2 components still tied, return the one containing
% the smallest node index).
%
% The are no restrictions on the image A except that it must be a 2D matrix,
% and the operator "==" must be defined on its entries.  If sorting of the
% components by size is requested or if the largest component is requested,
% double(A) must be computable.
%
% Usage:
%   c = find_components (A) ;       % just return nodes in the largest component
%   [p r nc G xy] = find_components (A) ;       % sorted by least node number

    
function [p, r, nc, G, xy] = find_components (A,sorted)
%FIND_COMPONENTS finds all connected components of an image.
% Two pixels in an image are in the same connected component if and only if
% they are adjacent and have the same value.  "Adjacent" in this context means
% north/south or east/west, not diagonally.  That is, A(2,3) is adjacent to
% A(2,2), A(2,4), A(1,3), and A(3,3) only, and is not adjacent to A(3,4).
%
% Let [p r] = find_components(A) where A is m-by-n.  The result is a permutation
% p and component boundaries r.  p is a permutation of 1:m*n, and refers to the
% linear indexing of A.  That is, A(i,j) is refered to as A(i+j*m) in the list
% p.  The kth connected component consists of A (p (r(k) : r(k+1)-1)).
% The number of connected components is nc = length (r) - 1.  The components
% are ordered by the smallest linear index in each component (assuming you have
% MATLAB 7.5 or later, which uses DMPERM from CSparse; otherwise the ordering
% is not defined).
%
% With a single output argument, c = find_components (A) just returns a list
% of the nodes in the largest component (the component with the largest value
% if ties, and if there are 2 components still tied, return the one containing
% the smallest node index).
%
% The are no restrictions on the image A except that it must be a 2D matrix,
% and the operator "==" must be defined on its entries.  If sorting of the
% components by size is requested or if the largest component is requested,
% double(A) must be computable.
%
% Usage:
%   c = find_components (A) ;       % just return nodes in the largest component
%   [p r nc G xy] = find_components (A) ;       % sorted by least node number
%   [p r nc G xy] = find_components (A, 1) ;    % sorted by size, ties by value
%   find_components (A) ;                       % just plot the graph
%
% Example:
%
%   A = [ 1 2 2 3
%         1 1 2 3
%         0 0 1 2
%         0 1 3 3 ]
%   [p r nc] = find_components (A,1)
%   [m n] = size (A) ;
%   for k = 1:nc
%       a = A (p (r (k))) ;
%       fprintf ('\ncomponent %d, size %d, value %d\n', k, r(k+1)-r(k), a) ;
%       C = nan (m,n) ;
%       C (p (r (k) : r (k+1)-1)) =  a ;
%       fprintf ('A = \n') ; disp (A) ;
%       fprintf ('the component = \n') ; disp (C) ;
%       input (': ', 's') ;
%   end