2

I added a data cursor in a Matlab figure, and this it the code shown when I clicked "Edit Text Update Function..."

function output_txt = myfunction(obj,event_obj)
% Display the position of the data cursor
% obj          Currently not used (empty)
% event_obj    Handle to event object
% output_txt   Data cursor text string (string or cell array of strings).

pos = get(event_obj,'Position');
output_txt = {['X: ',num2str(pos(1),4)],...
    ['Y: ',num2str(pos(2),4)]};
% If there is a Z-coordinate in the position, display it as well
if length(pos) > 2
    output_txt{end+1} = ['Z: ',num2str(pos(3),4)];
end

What I want to do here is replacing the characters 'X', 'Y' by the Greek character like 'alpha' or 'beta'. How can I do that?

Thank you!

casperOne
  • 73,706
  • 19
  • 184
  • 253
opmfan
  • 191
  • 1
  • 3
  • 14
  • 1
    possible duplicate of [How do I use TeX/LaTeX formatting for custom data tips in MATLAB?](http://stackoverflow.com/questions/1668071/how-do-i-use-tex-latex-formatting-for-custom-data-tips-in-matlab) – Amro Nov 14 '11 at 16:08
  • I thought this question sounded familiar! gnovice had an excellent answer: http://stackoverflow.com/questions/1668071/how-do-i-use-tex-latex-formatting-for-custom-data-tips-in-matlab/1668559#1668559 – Doresoom Nov 15 '11 at 16:07

1 Answers1

2

\alpha (and some LaTeX symbols) works in title and probably in this case too. Note: \Alpha is the capital greek letter, \alpha is the small one.

See this table.

EDIT : See also Amro comments to activate the (La)TeX interpreter.

Clement J.
  • 3,012
  • 26
  • 29
  • In addition, detexify (http://detexify.kirelabs.org/classify.html) is a nice tool for automatically finding LaTeX symbol definitions by drawing on a canvas. – petrichor Nov 14 '11 at 11:03
  • 1
    @ClementJ.: this won't work by default, you need to set the text interpreter to `'tex'`. See linked question – Amro Nov 14 '11 at 16:08
  • @Amro, 'tex' seems to be the default value of the parameter. Anyway you're right to point it. – Clement J. Nov 14 '11 at 17:01
  • 1
    @ClementJ.: although it is for normal text, that's not true for data-tips (again read gnovice's answer I linked to). Thus you have to explicitly set the interpreter to parse TeX/LaTeX: `set(findall(gcf, 'Type','text', 'Tag','DataTipMarker'), 'Interpreter','tex')` – Amro Nov 14 '11 at 17:50
  • very nice conclusion about text formatting for MATLAB, including detailed information about greek letters: http://www.mathworks.de/de/help/matlab/creating_plots/adding-text-to-graphs.html – mojjj Nov 20 '13 at 09:42