standard separation of x axis tick marks

조회 수: 3 (최근 30일)
Adam Dilley
Adam Dilley 2019년 7월 11일
댓글: Star Strider 2019년 7월 11일
Hello,
I'm writing a program for a class that plots a transfer function to the omega(rad/s) and the phase angle to omega(rad/s) but I'm running into the problem of the graph not looking the way it needs to. below is the code i wrote so you can see what the graph currently looks like and i figured out how to label the ticks correctly but HOW DO YOU GET THE TICKS SPACED EVENLY when the the numbers are xticks([10^0 10^2 10^4 10^6])?
% Input Variable Section:
R = 10000%input('What is the resistance (in ohms)? ');
L = 1%input('What is the inductance (in henries)? ');
omega1 = 1%input('what is the starting frequency (in radians/sec)? ');
omega2 = 1000000%input('what is the ending frequency (in radians/sec)? ');
dw = (omega2-omega1)/1000;
% Parameter Section:
omega = omega1:dw:omega2;
% Calculation Section:
T = R./(L.*omega);
H = 1./(sqrt(1+(T).^2));
decibels = 20.*log10(H);
phi = atand(T);
table = [omega',T',H',decibels',phi'];
% Output Variable Section:
subplot(1,2,1)
plot(omega,decibels),xlabel('Omega (rad/s)'),ylabel('Hv'),title('High Pass RL Filter Transfer Function')
xticks([10^0 10^2 10^4 10^6])
subplot(1,2,2)
plot(omega,phi), xlabel('Omega (rad/s)'),ylabel('Phase Angle'),title('High Pass RL Filter Phase Angle')
xticks([10^0 10^2 10^4 10^6])

채택된 답변

Star Strider
Star Strider 2019년 7월 11일
Plot them using semilogx:
% Output Variable Section:
subplot(1,2,1)
semilogx(omega,decibels),xlabel('Omega (rad/s)'),ylabel('Hv'),title('High Pass RL Filter Transfer Function')
xticks([10^0 10^2 10^4 10^6])
subplot(1,2,2)
semilogx(omega,phi), xlabel('Omega (rad/s)'),ylabel('Phase Angle'),title('High Pass RL Filter Phase Angle')
xticks([10^0 10^2 10^4 10^6])
Equivalently, you can use:
set(gca, 'XScale','log')
for each subplot.
  댓글 수: 2
Adam Dilley
Adam Dilley 2019년 7월 11일
Thank you so much! I looked this up in our text book and its not covered until our next chapter, I don't know why we had an assignment that needed this plot function before we covered it. It worked though, thanks again.
Star Strider
Star Strider 2019년 7월 11일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Bobby Huxford
Bobby Huxford 2019년 7월 11일
I believe you are looking to change the scale of the X-axis to log:
set(gca, 'XScale', 'log')
Full code:
% Input Variable Section:
R = 10000%input('What is the resistance (in ohms)? ');
L = 1%input('What is the inductance (in henries)? ');
omega1 = 1%input('what is the starting frequency (in radians/sec)? ');
omega2 = 1000000%input('what is the ending frequency (in radians/sec)? ');
dw = (omega2-omega1)/1000;
% Parameter Section:
omega = omega1:dw:omega2;
% Calculation Section:
T = R./(L.*omega);
H = 1./(sqrt(1+(T).^2));
decibels = 20.*log10(H);
phi = atand(T);
table = [omega',T',H',decibels',phi'];
% Output Variable Section:
subplot(1,2,1)
plot(omega,decibels),xlabel('Omega (rad/s)'),ylabel('Hv'),title('High Pass RL Filter Transfer Function')
xticks([10^0 10^2 10^4 10^6])
subplot(1,2,2)
plot(omega,phi), xlabel('Omega (rad/s)'),ylabel('Phase Angle'),title('High Pass RL Filter Phase Angle')
set(gca, 'XScale', 'log')
xticks([10^0 10^2 10^4 10^6])

카테고리

Help CenterFile Exchange에서 Switches and Breakers에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by