How to add hat symbol to "xtick"

3 views (last 30 days)
Jing Gao
Jing Gao on 25 Feb 2020
Commented: dpb on 26 Feb 2020
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!

Accepted Answer

dpb
dpb on 25 Feb 2020
Edited: dpb on 26 Feb 2020
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...
  2 Comments
Jing Gao
Jing Gao on 26 Feb 2020
Thank you a lot! And I also figure out that I can add text to the graph, this makes things easier.
dpb
dpb on 26 Feb 2020
Glad to help...and good luck w/ LaTeX syntax--it's even worse than regular expressions trying to figure out what will/won't work in the MATLAB implementation.
If this solves the problem, how about ACCEPT the answer so others will know is a solution...

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!