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;
1