How to plot both log scale in MATLAB
조회 수: 11 (최근 30일)
이전 댓글 표시
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
채택된 답변
Cris LaPierre
2022년 8월 23일
편집: Cris LaPierre
2022년 8월 23일
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
Cris LaPierre
2022년 8월 24일
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;
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Log Plots에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


