function varargout=mplot(x,y,idx,opt,varargin)
% mplot <Multi-plot.>
% Usage:: varargout=mplot(x,y,idx,opt,varargin)
%

% revision history:
% 03/28/03 Mark D. Shattuck <mds> mplot.m

%% Main

Np=length(idx);
color=double(dec2bin(0:6))-double('0');

nin=nargin-length(varargin);
if(nin<4)
  opt=cell(1,Np);
  [opt{:}]=deal('');
elseif(nin==4)
  if(~iscell(opt))
    tmp=opt;
    opt=cell(1,Np);
    [opt{:}]=deal(tmp);
  end
else
  error('Too many inputs!');
end

ihold=ishold;


hext=plot(x(idx{1}),y(idx{1}),opt{1},varargin{:});
nextp=length(hext)-1;
h=zeros(1,Np+nextp);
h(1)=hext(1);
if(isempty(opt{1}))
  set(h(1),'color',color(2,:))
else  
  if(max(ismember(opt{1},'bgrcmykw'))==0);
    set(h(1),'color',color(2,:))
  end
end
hold on;
for np=2:Np
  h(np)=plot(x(idx{np}),y(idx{np}),opt{np});
  if(isempty(opt{1}))
    set(h(np),'color',color(mod(np+1-1,7)+1,:));
  else
    if(max(ismember(opt{np},'bgrcmykw'))==0);
      set(h(np),'color',color(mod(np+1-1,7)+1,:));
    end
  end
end
if(ihold==0)
  hold off;
end

if(nargout==1)
  h(Np+1:Np+nextp)=hext(2:end);
  varargout(1)={h};
end
