Plotting resistors and capacitors in matlab
Afficher commentaires plus anciens
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?
Réponses (2)
Image Analyst
le 21 Oct 2013
0 votes
You can use the line() command. Anything wrong with that?
2 commentaires
Jerry
le 21 Oct 2013
Image Analyst
le 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.
Youssef Khmou
le 21 Oct 2013
Modifié(e) : Youssef Khmou
le 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 commentaires
Jerry
le 21 Oct 2013
Image Analyst
le 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.
Catégories
En savoir plus sur Spline Postprocessing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!