standard separation of x axis tick marks

4 visualizaciones (últimos 30 días)
Adam Dilley
Adam Dilley el 11 de Jul. de 2019
Comentada: Star Strider el 11 de Jul. de 2019
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])

Respuesta aceptada

Star Strider
Star Strider el 11 de Jul. de 2019
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 comentarios
Adam Dilley
Adam Dilley el 11 de Jul. de 2019
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 el 11 de Jul. de 2019
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (1)

Bobby Huxford
Bobby Huxford el 11 de Jul. de 2019
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])

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by