Plotting resistors and capacitors in matlab

I was wondering how you would plot the general shape of resistors and capacitors in matlab. For resistors, I came up with the following script to plot the zig zag shape: function draw_resistor(x,y,len) points=8; scale=2; vec=1:points; X=linspace(x,x+len,points); Y=zeros(1,points)+y; Y(rem(vec,2)==1)=y-len/scale/2; Y(rem(vec,2)==0)=y+len/scale/2; Y(1)=y; Y(points)=y; plot(X,Y);
However I am not sure how to draw the shape for capacitors? I know I need to plot two parallel lines but I am not too sure how to do so? Can someone help?

Answers (2)

You can use the line() command. Anything wrong with that?

2 Comments

I'm not sure how I would do so.
Well you're using plot(x,y) to draw zig zags, right? Well you just use line to draw the two lines:
line([x1 x2], [y1 y2]); % One plate of the capacitor.
line([x3 x4], [y3 y4]); % Other plate of the capacitor.

Sign in to comment.

Jerry,
Here are, quickly, two ways to work around :
% First way: too bad use HEAVISIDE instead or increase resolution
x0=0;x1=10;y0=0;y1=10;
N=100;
Capacitor=zeros(1,N);
Position=[4 5]; % Position of capacitor
Capacitor(0.4*N)=10;
Capacitor(0.5*N)=10;
figure, plot(Capacitor)
% 2nd : Better that 1 :
H=ones(100);
H(end/2,end/2:end/2+10)=0;
H(end/2+10,end/2:end/2+10)=0;
figure, surface(H)
shading interp

2 Comments

I see, but how would I rewrite this to include the variables x, y, and len as shown in the script I wrote for resistors?
We don't know where in the plot/graph/image you want this capacitor symbol to appear so you have to specify the x and y to locate the lines where you want. We cannot know that.

Sign in to comment.

Categories

Asked:

on 21 Oct 2013

Commented:

on 21 Oct 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!