필터 지우기
필터 지우기

How to set axis as -pi to pi ?

조회 수: 197 (최근 30일)
Leena
Leena 2014년 3월 23일
댓글: ibrahim guler 2020년 5월 6일
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.

채택된 답변

Mischa Kim
Mischa Kim 2014년 3월 23일
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
set(gca,'XTick',0:pi/2:2*pi)
set(gca,'XTickLabel',{'0','pi/2','pi','3*pi/2','2*pi'})
  댓글 수: 1
Leena
Leena 2014년 3월 23일
It worked. Thank u so much :)

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

추가 답변 (2개)

Chris Jennings
Chris Jennings 2019년 1월 4일
편집: Chris Jennings 2019년 1월 4일
or better still use \pi to generate nice pi characters, for example:
set(gca,'XTick',-2*pi:pi:2*pi)
ax.XTickLabel = {'-2\pi','-\pi','0','\pi','2\pi'};

Ítalo Pedrosa
Ítalo Pedrosa 2019년 9월 11일
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,'XTick',axisX)
set(gca,'XTickLabel', string(sym(axisX)))
grid on
Solved my problem for any situations. But you need the syms
  댓글 수: 1
ibrahim guler
ibrahim guler 2020년 5월 6일
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.

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

카테고리

Help CenterFile Exchange에서 Antenna and Array Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by