Problem in plotting using semilogx() function
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/145763/image.jpeg)
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
0 commentaires
Réponse acceptée
Rick Rosson
le 19 Oct 2014
Modifié(e) : Rick Rosson
le 19 Oct 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');
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Plot Customization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!