How to plot both log scale in MATLAB
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kamran Khan
le 23 Août 2022
Commenté : Cris LaPierre
le 24 Août 2022
I'm trying to plot the below equation vs frequency in both log scale using loglog() function on x and y axes.
c_lead = 0.4018e-12;
l_lead = 43.333e-9;
wc = 2.488e+10;
R = 100;
w = 10000:10:1000000000;
x = ((w./wc).^2)./((w.*c_lead).*(1+((w./wc).^2)));
Zab = R./(1+((w./wc).^2)) + (w.*l_lead - x)*1i;
loglog(w, (abs(Zab)));
title('R = 100ohm');
xlabel('Frequency (in Hz)','FontSize',12,'FontWeight','bold','Color','r');
ylabel('Impedance (in ohm)','FontSize',12,'FontWeight','bold','Color','r');
grid on;
However, as you can see, there is no log scale effect on the y axis. How to fix this? Thanks.


0 commentaires
Réponse acceptée
Cris LaPierre
le 23 Août 2022
Modifié(e) : Cris LaPierre
le 23 Août 2022
The scale is still 'log'. However, because MATLAB automatically scales the axes to fit the data, the plot appears to be using cartesian scaling because your Y data ranges from 100 to 107. See this example. You could adjust the YLmin so that it is easier to see the logarithmic scale.
As an aside, I suggest using logspace to create w. The vector will be much smaller, making it much easier to plot the results (I was getting errors running your code on my laptop).
c_lead = 0.4018e-12;
l_lead = 43.333e-9;
wc = 2.488e+10;
R = 100;
w = logspace(4,9,10000);
x = ((w./wc).^2)./((w.*c_lead).*(1+((w./wc).^2)));
Zab = R./(1+((w./wc).^2)) + (w.*l_lead - x)*1i;
loglog(w, (abs(Zab)));
title('R = 100ohm');
xlabel('Frequency (in Hz)','FontSize',12,'FontWeight','bold','Color','r');
ylabel('Impedance (in ohm)','FontSize',12,'FontWeight','bold','Color','r');
grid on;
Compare that to this plot
figure
loglog(w, (abs(Zab)));
title('R = 100ohm');
xlabel('Frequency (in Hz)','FontSize',12,'FontWeight','bold','Color','r');
ylabel('Impedance (in ohm)','FontSize',12,'FontWeight','bold','Color','r');
grid on;
ylim([1e2 1e4])
2 commentaires
Cris LaPierre
le 24 Août 2022
Sure. In that plot, I had changed the range of your data to make the logarithmic scale more obvious.
c_lead = 0.4018e-12;
l_lead = 43.333e-9;
wc = 2.488e+10;
R = 100;
w = logspace(4,12,10000); % <---------- Changed to 10^12
x = ((w./wc).^2)./((w.*c_lead).*(1+((w./wc).^2)));
Zab = R./(1+((w./wc).^2)) + (w.*l_lead - x)*1i;
loglog(w, (abs(Zab)));
title('R = 100ohm');
xlabel('Frequency (in Hz)','FontSize',12,'FontWeight','bold','Color','r');
ylabel('Impedance (in ohm)','FontSize',12,'FontWeight','bold','Color','r');
grid on;
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Log Plots dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


