Make x-axis display multiple times the interval of 0 to 360 degrees
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Theo Pap
il 14 Dic 2018
Commentato: Cris LaPierre
il 19 Nov 2020
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:
2 Commenti
Risposta accettata
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
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
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)];
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Axis Labels in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!