MATLAB: How to place Tex strings into figure axes properties

label;MATLABsymbolstick

I would like to place Tex strings into figure axes properties, 'XTickLabels' or 'YTickLabels'.
Here is an example. I would like the following:
x=1:10;
y=sin(x);
plot(x,y)
set(gca,'XTick',[0 pi 2*pi])
set(gca,'XTickLabel',[0 pi 2*pi])
To enhance to:
x=1:10;
y=sin(x);
plot(x,y)
set(gca,'XTick',[0 pi 2*pi])
set(gca,'XTickLabel','0|\pi|2*\pi')
Where the X label would show :
0 pi(greek symbol) 2 * pi(greek symbol).
Currently, it shows :
0 /pi 2*/pi.

Best Answer

Here is one possible way to do this:
plot(1:5)
% Set the tick locations and remove the labels
set(gca,'XTick',1:5,'XTickLabel','')
% Define the labels
lab = {'-\pi ';'-\pi/2';'0 ';'\pi/2 ';'\pi '};
% Estimate the location of the labels based on the position
% of the xlabel
hx = get(gca,'XLabel'); % Handle to xlabel
pos = get(hx,'Position');
y = pos(2);
% Place the new labels
for i = 1:size(lab,1)
t(i) = text(i,y,lab(i,:));
end
Related Question