I have a series of values in units of π that I want to label on the x-axis using xticklabels(mylabels). I want to typeset the units using LaTeX command. Thus I specified latex as the interpretor for my tick labels using the commands:
ax=gca;
ax.TickLabelInterpreter='Latex';
The labels are displayed correctly when I set mylabels as cell array of character vectors as follows:
mylabels={'$-2\pi$','$-\frac{3\pi}{2}$','$-\pi$','$-\frac{\pi}{2}$','0~~~~','$\frac{\pi}{2}$','$\pi$','$\frac{3\pi}{2}$','$2\pi$'};
However, when I specify mylabels as a cell array of strings, or a string array, or a character array as follows, the labels are not displayed on the x-axis.
- mylabels=['$-2\pi$','$-\frac{3\pi}{2}$','$-\pi$','$-\frac{\pi}{2}$','0~~~~','$\frac{\pi}{2}$','$\pi$',... '$\frac{3\pi}{2}$','$2\pi$'];
- mylabels={"-2\pi","-\frac{3\pi}{2}","-\pi","-\frac{\pi}{2}","0~~~~", "\frac{\pi}{2}","\pi","\frac{3\pi}{2}","2\pi"};
- mylabels=["-2\pi","-\frac{3\pi}{2}","-\pi","-\frac{\pi}{2}","0~~~~","\frac{\pi}{2}","\pi","\frac{3\pi}{2}","2\pi"];
I would like to understand what's the problem here.
A complete MWE is given as follows:
figure;
xlabel("x")
ylabel("y")
xlim([-2*pi 2*pi])
xticks(-2*pi:pi/2:2*pi)
mylabels={'$-2\pi$','$-\frac{3\pi}{2}$','$-\pi$','$-\frac{\pi}{2}$','0~~~~','$\frac{\pi}{2}$','$\pi$','$\frac{3\pi}{2}$','$2\pi$'};
xticklabels(mylabels)
ax=gca;
ax.TickLabelInterpreter='Latex';
Thank you very much in advance!