Problem in plotting using semilogx() function

5 次查看(过去 30 天)
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

采纳的回答

Rick Rosson
Rick Rosson 2014-10-19
编辑:Rick Rosson 2014-10-19
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');

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Plot Customization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by