How to use greek letters in GUIDE for static text elements? [Not a question]

5 views (last 30 days)
While I was writing my final thesis I made a GUI with GUIDE but I had some issues with the use of greek letters, subscripts and so inside the static text elements. I wanted to write them in LaTeX format and assign them to the static text, something like:
set(handles.tex1, 'String', '\alpha_{0}');
But it didn't work, so after a while I realized it was because there are some elements inside GUIDE who allows LaTeX writing and some others who doesn't, and the Static Text element is one who doesn't. So, in order to use greek letters as if we were using a Static Text we must replace it for the Axes element (one who does accept LaTeX writing). What you must do is this:
1.- Create a tiny axes element, just as if it were a static text element and give it a tag (or don't, it doesn't matter but sometimes it makes things easier) in the *.fig file.
2.- Write this code for every axes element just after your GUI's Opening Function in the *.m file:
(Imagine we have created an axes element with the tag "test1" and we want the alpha letter with the subscript 0)
axes(handles.test1);
text('Interpreter','LaTex',...
'string','$\alpha_{0}$',...
'FontSize',13)
axis off
3.- Run your GUI
What we're doing is to use the axes element for displaying greek letters or equations in LaTeX format. After this you should have a nice looking greek letter with a subscript (you can adjust Fontsize for a bigger or smaller label), then all you have to do if you want to create more labels with greek letters is to create as many Axes elements as you need, give them tags, and write the same code in your *.m file just after the previous one. Example
function GreekLettersGUI_OpeningFcn(hObject, eventdata, handles, varargin)
axes(handles.test1);
text('Interpreter','LaTex',...
'string','$\alpha_{0}$',...
'FontSize',13)
axis off
axes(handles.test2);
text('Interpreter','LaTex',...
'string','$\theta_{tw}$',...
'FontSize',13)
axis off
axes(handles.test3);
text('Interpreter','LaTex',...
'string','${\beta_{0}^2}$',...
'FontSize',13)
axis off
It was the easiest way I found so I wanted to share it.

Answers (0)

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!