MATLAB: How to add hat symbol to “xtick”

plottick

Hi there, I want to add a hat to my xtick:
xticks([B_hat(3),B_hat(2), B_hat(1)])
xticklabels({'\hat B_H' 'B_M' 'B_L'})
I've tried
yticklabels({'V_U'},'Interpreter', 'latex');
or codes like:
set(Figure1,'defaulttextinterpreter','latex');
Both do not work. Anyone has an idea? Thank you!

Best Answer

Have to escape LaTex sequences with "$$" before and after...try something like
hAx=axes;
xlim([1 3]); xticks([1:3]) % a sample axes object
lbls=['A':'C'].'; % wanted text labels to apply
fmt='$$\\hat{%c}$$'; % formatting for the carat
txt=arrayfun(@(s) sprintf(fmt,s),lbls,'UniformOutput',false); % generate the labels
hAx.TickLabelInterpreter='latex';
hAx.XTickLabel=txt; % and apply them...
Salt to suit...