How to set axis as -pi to pi ?

490 visualizaciones (últimos 30 días)
Leena el 23 de Mzo. de 2014
Comentada: ibrahim guler el 6 de Mayo de 2020
Hi. I have attached my program for the radiation pattern of the horn antenna. I want to have a graph which should have axis from -pi to pi. but I cant do it. When I use set(gca,'XTick',-pi:pi/2:pi) set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'}) command, the figure appears to be some what like I have attached. Please help.

Respuesta aceptada

Mischa Kim
Mischa Kim el 23 de Mzo. de 2014
Leena, in the code you are converting the angels (x-axis) from rad to deg. Also it seems like the angular range is between 0 and 360 deg. Therefore,
  • remove the conversion factor, e.g., e = theta, or simply use theta for plotting,
  • and set
  1 comentario
Leena el 23 de Mzo. de 2014
It worked. Thank u so much :)

Iniciar sesión para comentar.

Más respuestas (2)

Chris Jennings
Chris Jennings el 4 de En. de 2019
Editada: Chris Jennings el 4 de En. de 2019
or better still use \pi to generate nice pi characters, for example:
ax.XTickLabel = {'-2\pi','-\pi','0','\pi','2\pi'};

Ítalo Pedrosa
Ítalo Pedrosa el 11 de Sept. de 2019
I had the same problem. Reading the comments, I did:
function plot_radian(X, int, Y)
axisX = X(1):int:X(end);
plot(X, Y)
set(gca,'XTickLabel', string(sym(axisX)))
grid on
Solved my problem for any situations. But you need the syms
  1 comentario
ibrahim guler
ibrahim guler el 6 de Mayo de 2020
If you have so many points to plot it would crash your program. Therefore, you should add some restriction in the begining of the function I think.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by