Plotting resistors and capacitors in matlab

5 views (last 30 days)
Jerry
Jerry on 21 Oct 2013
Commented: Image Analyst on 21 Oct 2013
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)

Image Analyst
Image Analyst on 21 Oct 2013
You can use the line() command. Anything wrong with that?
  2 Comments
Jerry
Jerry on 21 Oct 2013
I'm not sure how I would do so.
Image Analyst
Image Analyst on 21 Oct 2013
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.


Youssef  Khmou
Youssef Khmou on 21 Oct 2013
Edited: Youssef Khmou on 21 Oct 2013
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
Jerry
Jerry on 21 Oct 2013
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?
Image Analyst
Image Analyst on 21 Oct 2013
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

Find more on Spline Postprocessing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!