How to write a fraction on xticklabel?

this is my code:
%plot absolute value of 4 filters%
f = linspace(-pi, pi, 80);
LPFs = figure();
suptitle('Absolute Frequency Responses of LPFs');
%H2%
subplot(2,2,1)
FT_h2 = abs(fftshift(fft(h2)));
xlabel('\omega [rad]');
ylabel('Magnitude of H2');
plot(f,FT_h2);
ticklabelinterpreter = 'latex';
xticks([-pi -pi/2 -pi/3 -pi/4 -pi/6 0 pi/6 pi/4 pi/3 pi/2 pi]);
xticklabels({'-\pi','$\frac{-\pi}{2}$','-\pi/3','-\pi/4','-\pi/6','0','\pi/6','\pi/4','\pi/3','\pi/2','\pi'});
but the result is:
Screen Shot 2019-06-09 at 21.18.43.png

 Accepted Answer

xticklabels({'$-\pi$','$\frac{-\pi}{2}$','$-\pi/3$','$-\pi/4$','$-\pi/6$','$0$','$\pi/6$','$\pi/4$','$\pi/3$','$\pi/2$','$\pi$'});
set(gca,'TickLabelInterpreter', 'latex')
You will probably want to convert the rest to \frac for consistency.

1 Comment

I cant seem to understand the differance between TickLabelInterpreter and xticks or xticklabels.
Why does the first should be set with the set function and the laters are set like a function?

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!