function resistor(varargin)
%RESISTOR  Draw a resistor

%   Author(s): A. DiVergilio
%   Copyright 1986-2000 The MathWorks, Inc.
%   $Revision: 1.3 $  $Date: 2000/07/21 22:34:55 $

%---Default properties
p = struct(...
   'Parent',[],...
   'Position',[2 2],...
   'Size',1,...
   'Angle',0,...
   'LineWidth',2,...
   'LineStyle','-',...
   'Color','k',...
   'Tag','',...
   'Clipping','off');
plist = fieldnames(p);

%---Merge user-specified properties
for i=1:2:nargin-1
   Property = pnmatch(varargin{i},plist);
   Value = varargin{i+1};
   p = setfield(p,Property,Value);
end
if isempty(p.Parent), p.Parent = gca; end

%---Draw a line
x = p.Size*[0 .2 .25 .35 .45 .55 .65 .75 .8 1];
y = p.Size*[0 0 .2 -.2 .2 -.2 .2 -.2 0 0];
r = sqrt(x(2:end).^2+y(2:end).^2);
a0 = atan(y(2:end)./x(2:end));
line(...
   'Parent',p.Parent,...
   'XData',p.Position(1)+[0 r.*cos(a0+p.Angle*pi/180)],...
   'YData',p.Position(2)+[0 r.*sin(a0+p.Angle*pi/180)],...
   'LineWidth',p.LineWidth,...
   'LineStyle',p.LineStyle,...
   'Color',p.Color,...
   'Tag',p.Tag,...
   'Clipping',p.Clipping);
