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

8 visualizzazioni (ultimi 30 giorni)
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 Commenti
Theo Pap
Theo Pap il 14 Dic 2018
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

Accedi per commentare.

Risposta accettata

Cris LaPierre
Cris LaPierre il 14 Dic 2018
Modificato: Cris LaPierre il 14 Dic 2018
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 Commenti
Martin Offterdinger
Martin Offterdinger il 19 Nov 2020
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 il 19 Nov 2020
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)];

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by