Customizing the tick values and labels along x axis

13 visualizaciones (últimos 30 días)
Susan
Susan el 23 de Jun. de 2021
Comentada: Star Strider el 23 de Jun. de 2021
Hi All,
When I plot(1:20, f), the x-axis are shown from 1 to 20. However my real x values are
x =
Columns 1 through 13
30.0000 28.0000 26.0000 24.0000 22.0000 20.0000 18.0000 16.0000 14.0000 12.0000 10.0000 8.0000 6.0000
Columns 14 through 20
4.0000 2.0000 1.0000 0.8000 0.6000 0.4000 0.2000
and I'd like the real x values to show up in the figure. To do so, I used
xticks([x])
and got an error that says
Value must be a numeric vector whose values increase.
Any idea how I can fix this issue?
Thanks in advance

Respuesta aceptada

Star Strider
Star Strider el 23 de Jun. de 2021
Editada: Star Strider el 23 de Jun. de 2021
Try something like this:
x = [30.0000 28.0000 26.0000 24.0000 22.0000 20.0000 18.0000 16.0000 14.0000 12.0000 10.0000 8.0000 6.0000 4.0000 2.0000 1.0000 0.8000 0.6000 0.4000 0.2000];
figure
plot(rand(1,20))
set(gca, 'XTick',1:20, 'XTickLabel',compose('%g',x))
EDIT — (23 Jun 2021 at 22:21)
Since I’m not certain what you’re actually doing, another option is:
x = [30.0000 28.0000 26.0000 24.0000 22.0000 20.0000 18.0000 16.0000 14.0000 12.0000 10.0000 8.0000 6.0000 4.0000 2.0000 1.0000 0.8000 0.6000 0.4000 0.2000];
figure
plot(x, rand(1,20))
set(gca, 'XTick',sort(x), 'XDir','reverse')
.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by