Borrar filtros
Borrar filtros

Problem in plotting using semilogx() function

1 visualización (últimos 30 días)
PVR
PVR el 19 de Oct. de 2014
Editada: Rick Rosson el 19 de Oct. de 2014
I need to plot a graph between w(frequency) and Mdb(Magnitude in db) using semilogx() function for different values of w. The output of graph is null. It shows nothing and there are no errors displayed. Where did I go wrong.
R=zeros(1,10000);
I=zeros(1,10000);
Mag=zeros(1,10000);
Z=zeros(1,10000);
Y=zeros(1,10000);
Mdb=zeros(1,10000);
for *w* = 0.1:0.01:10
R=(256-(16*w^2))/((16-(w^2))^2+(10*w)^2);
I=-160*w/((16-w^2)^2+(10*w)^2);
Mag=sqrt(R^2+I^2);
Z=atan2(I,R);
Y=Z*180/pi;
*Mdb* =20*log10(Mag); *bold*
plot(w,Mdb,'g');
semilogx(w,Mdb);
end

Respuesta aceptada

Rick Rosson
Rick Rosson el 19 de Oct. de 2014
Editada: Rick Rosson el 19 de Oct. de 2014
Vectorized code, no for-loop necessary:
w = 0.1:0.01:10;
R = (256-(16*w.^2))./((16-(w.^2)).^2+(10*w).^2);
I = -160*w./((16-w.^2).^2+(10*w).^2);
X = complex(R,I);
Mag = abs(X);
Mdb = 20*log10(Mag);
phi = angle(X)*180/pi;
figure;
ax(1) = subplot(2,1,1);
semilogx(w,Mdb);
grid on;
xlabel('Frequency');
ylabel('Magnitude in dB');
ax(2) = subplot(2,1,2);
semilogx(w,phi);
grid on;
xlabel('Frequency');
ylabel('Phase angle in degrees');
linkaxes(ax,'x');

Más respuestas (0)

Categorías

Más información sobre Plot Customization en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by