-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathresistor.m
42 lines (38 loc) · 1.05 KB
/
resistor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function resistor(varargin)
%RESISTOR Draw a resistor
% Author(s): A. DiVergilio
% Copyright 1986-2002 The MathWorks, Inc.
% $Revision: 1.6 $ $Date: 2002/04/10 06:42:00 $
%---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.(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);