Unable to format fractions in xticklabels

11 views (last 30 days)
Hi, so I'm trying to write a fraction in 'xticklabels', I already tried to write
$\frac{a}{b}$
but it doesn't seem to work, any suggestions? Code section is given below:
figure(2);
plot(y(:,3),y(:,4));
xticks([-pi -3*pi/4 -pi/2 -pi/4 0 pi/4 pi/2 3*pi/4 pi])
xticklabels({'-\pi','$\frac{-3\pi}{4}$','-\frac{\pi}{2}','-\pi/4','0','\pi/4','\pi/2','3\pi/4','\pi'})
title('Angular Velocity Graph')
xlabel('Angle (rad)')
ylabel('Angular Velocity (rad s^{-1})')

Accepted Answer

Ameer Hamza
Ameer Hamza on 7 Nov 2020
You need to use latex interpreter. Following shows how to do that
figure(2);
ax = axes();
plot(y(:,3),y(:,4));
xlim([-pi pi])
xticks([-pi -3*pi/4 -pi/2 -pi/4 0 pi/4 pi/2 3*pi/4 pi])
xticklabels({'$-\pi$','$\frac{-3\pi}{4}$','$-\frac{\pi}{2}$','$-\pi/4$','$0$','$\pi/4$','$\pi/2$','$3\pi/4$','$\pi$'})
ax.XAxis.TickLabelInterpreter = 'latex';
title('Angular Velocity Graph')
xlabel('Angle (rad)')
ylabel('Angular Velocity (rad s^{-1})')

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!