MATLAB: How to put a hat on letters in a legend

hatlegendtext;

Hey everyone,
I am trying to create a legend for one of my graphs that contains two entries: p and p^^CS – I want a hat on the p and I also want CS in the index….
Can someone tell me how to do that??
Thanks a lot!

Best Answer

You should use the LaTeX interpreter:
legend({'$\hat{p}^{CS}$'},'Interpreter','latex')