function plotpoints(varargin)
%   plotpoints(P1,P2,...,Pn) 
%   plotpoints(P1,P2,...,Pn,spec)    where spec is e.g. 'ro:'
%   plotpoints([P1,P2,...,Pn])
%   plotpoints([P1,P2,...,Pn],spec)
% plots points P1,P2,...,Pn which are *COLUMN* vectors of length 2 or 3
%
% By default the points are connected by lines. To get a closed polygon, repeat
% the first point: plotpoints(P1,P2,...,Pn,P1])
%
% You can get different styles by using an additional argument:
%   plotpoints(P1,P2,...,Pn,'o') 
%      plots the points as small circles, and does not connect them,
%   plotpoints(P1,P2,...,Pn,'r*:') 
%      plots the points as red stars, and connects them with a dotted line.
% Type   help plot   for more options.
%
% Examples
%   plotpoints([1;2],[3;4],[2;1])                     % plot line from (1,2) to (3,4) to (2,1)   
%   plotpoints([1;2],[3;4],[2;1],'r*:')               % mark points with *, dotted line, red
%   plotpoints([1;2],[3;4],[2;1],'r--','LineWidth',3) % use thick red dashed line
%   plotpoints([1;2;3],[3;4;1],[2;1;0]); nice3d % line from (1,2,3) to (3,4,1) to (2,1,0) 

% scan arguments until we find string or end
for k=1:nargin
  if isstr(varargin{k})
    k = k - 1;                % varargin{k} is last nonstring argument
    break
  end
end
if k == 0
  error('first argument has to be vector or matrix')
end
pts = horzcat(varargin{1:k});
d = size(pts,1);
if d==2
  plot(pts(1,:),pts(2,:),varargin{(k+1):end});
elseif d==3
  plot3(pts(1,:),pts(2,:),pts(3,:),varargin{(k+1):end});
else
  error('columns must have length 2 or 3')
end
