How to plot both log scale in MATLAB

11 ビュー (過去 30 日間)
Kamran Khan
Kamran Khan 2022 年 8 月 23 日
コメント済み: Cris LaPierre 2022 年 8 月 24 日
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.

採用された回答

Cris LaPierre
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 件のコメント
Kamran Khan
Kamran Khan 2022 年 8 月 24 日
Hi. Can you post the previous answer? I think the graph was better in that. Thanks.
Cris LaPierre
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 ExchangeLog Plots についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by