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: apcluster.m
    path of file: ./repos/scGEAToolbox/+ten
    
    the code of the file until where you have to start completion: %
% [idx,netsim,dpsim,expref]=apcluster(s,p)
%
% APCLUSTER uses affinity propagation (Frey and Dueck, Science,
% 2007) to identify data clusters, using a set of real-valued
% pair-wise data point similarities as input. Each cluster is
% represented by a data point called a cluster center, and the
% method searches for clusters so as to maximize a fitness
% function 
    
function [idx, netsim, i, unconverged, dpsim, expref] = apcluster(s, p, varargin)

% Handle arguments to function
if nargin < 2 error('Too few input arguments');
else
    maxits = 500;
    convits = 50;
    lam = 0.5;
    plt = 0;
    details = 0;
    nonoise = 0;
    i = 1;
    while i <= length(varargin)
        if strcmp(varargin{i}, 'plot')
            plt = 1;
            i = i + 1;
        elseif strcmp(varargin{i}, 'details')
            details = 1;
            i = i + 1;
        elseif strcmp(varargin{i}, 'sparse')
            [idx, netsim, dpsim, expref] = apcluster_sparse(s, p, varargin{:});
            return;
        elseif strcmp(varargin{i}, 'nonoise')
            nonoise = 1;
            i = i + 1;
        elseif strcmp(varargin{i}, 'maxits')
            maxits = varargin{i+1};
            i = i + 2;
            if maxits <= 0 error('maxits must be a positive integer'); end