How to plot both log scale in MATLAB

11 views (last 30 days)
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.

Accepted Answer

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

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!