Make x-axis display multiple times the interval of 0 to 360 degrees

조회 수: 10 (최근 30일)
Theo Pap
Theo Pap 2018년 12월 14일
댓글: Cris LaPierre 2020년 11월 19일
So, I am trying to make a figure, which displays a periodic signal, but instead of time, I want x-axis to display degrees.
The thing is that I cannot figure out a way for the x-axis to display multiple times the interval of 0 to 360 degrees. I only can create the following
mod(x_axis,360) obviously doesn't work
Any ideas?
EDIT
Just to be clear, I want to display something like that:
wrong_kindofright.png
  댓글 수: 2
TADA
TADA 2018년 12월 14일
Why Don't You just Make X 0:1080 Degrees?
Theo Pap
Theo Pap 2018년 12월 14일
I don't understand what you are saying... x is from 0 to 1800 degrees, but I want for the x axis to display multiple times the interval from 0 to 360. Like the following (by photoshop - not to scale - obviously wrong phase)
wrong_kindofright.png

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

채택된 답변

Cris LaPierre
Cris LaPierre 2018년 12월 14일
편집: Cris LaPierre 2018년 12월 14일
Labels and ticks are independent. You could set all the labels, but this does not affect where the corresponding tick is placed, as you can observe in your 3rd plot. That is set by XTick, so make sure your labels match your ticks, or play it safe and set your ticks at the same time:
ax = gca;
ax.XTick = 0:180:1800;
ax.XTickLabel = {0, 180, 360, 180, 360, 180, 360, 180, 360};
You could just set a pattern that repeats. The problem here, of course, is that if you start with zero, the zero will repeat.
ax.XTick = ax.XLim(1):120:ax.XLim(2);
ax.XTickLabel = [ax.XLim(1), 120, 240];
  댓글 수: 4
Martin Offterdinger
Martin Offterdinger 2020년 11월 19일
Dear Chris,
Unfortunately it did not work... Error message
'Index in position 1 is invalid. Array indices must be positive integers or logical values.'
My x-Values range from 0 to 1.9936 in intervalls of 0.0032; 624 values. Thereafter the x-Values repeat starting at 0 again (100 times in total).
Many thanks!
Martin
Cris LaPierre
Cris LaPierre 2020년 11월 19일
That's what I get for not testing the code first. It includes 0. You'll have to skip the first one. I don't include the X value in my plot command, so it will use index number to plot the Y values. There is no index of 0, so that point will be empty. I then capture the index values displaying on the plot, and use them to replace the tick labels with the corresponding x values.
data(:,1)=repmat((1:10)',5,1);
data(:,2)=rand([50 1]);
plot(data(:,2))
ax=gca;
ind = ax.XTick(2:end);
ax.XTickLabel=[0; data(ind,1)];

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by