How to plot both log scale in MATLAB

11 Ansichten (letzte 30 Tage)
Kamran Khan
Kamran Khan am 23 Aug. 2022
Kommentiert: Cris LaPierre am 24 Aug. 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.

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 23 Aug. 2022
Bearbeitet: Cris LaPierre am 23 Aug. 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 Kommentare
Kamran Khan
Kamran Khan am 24 Aug. 2022
Hi. Can you post the previous answer? I think the graph was better in that. Thanks.
Cris LaPierre
Cris LaPierre am 24 Aug. 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;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Log Plots finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by