How can I write Greek letters in a Static Text box in GUIDE in MATLAB 7.1 (R14SP3)?

61 views (last 30 days)
I would like to write Greek letters (or other LaTex symbols) like "alpha" in a Static Text Box in GUIDE.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 14 May 2018
UICONTROLs do not support TeX or LaTeX symbols.
To work around this limitation, one can use a TEXT object which does support LaTeX. Note that the TEXT object is not accessible in GUIDE though. Therefore you can use the following piece of code in your figure's OpeningFcn to automatically replace certain Static Text UICONTROLs with TEXT objects:
% TEXT annotations need an axes as parent so create an invisible axes which
% is as big as the figure
handles.laxis = axes('parent',hObject,'units','normalized','position',[0 0 1 1],'visible','off');
% Find all static text UICONTROLS whose 'Tag' starts with latex_
lbls = findobj(hObject,'-regexp','tag','latex_*');
for i=1:length(lbls)
l = lbls(i);
% Get current text, position and tag
set(l,'units','normalized');
s = get(l,'string');
p = get(l,'position');
t = get(l,'tag');
% Remove the UICONTROL
delete(l);
% Replace it with a TEXT object
handles.(t) = text(p(1),p(2),s,'interpreter','latex');
end
Place this piece of code right before the following line in the OpeningFcn:
% Update handles structure
guidata(hObject, handles);
Further in GUIDE give the Static Text boxes which need to be rendered using LaTeX, a 'Tag' which starts with latex_.
  1 Comment
PkStefan
PkStefan on 14 Jun 2017
Hi! In my case I designed a panel in which I placed a Static Text UICONTROL. It works fine with replacing the UICONTROL with a TEXT Object using the code above but the position will not be where the Static Text is placed. How can I replace it in the right Position while using a panel?
Thanks for your help!

Sign in to comment.

More Answers (2)

Benjamin Windheim
Benjamin Windheim on 26 Jan 2016

You also need to start the mathematical input mode. So the string (of the static text box in the Property Inspector) has to be like $\pi$, $\lambda$, $a^2+b^2=c^2$ or every other latex string you want to display.

  2 Comments
Natch Ruengsakulrach
Natch Ruengsakulrach on 27 Sep 2016
text('position',[0.8 0.9 0],'interpreter','latex','string','\fontsize{12}{0}\selectfont$xxx$\fontsize{8}{0}\selectfont$yyyy$');

Sign in to comment.


Baha411
Baha411 on 28 Feb 2019
I did a similar thing as following:
set(hObject,'units','normalized');
text0 = get(hObject,'string');
position0 = get(hObject,'position');
tag0 = get(hObject,'tag');
delete(hObject);
text('position',position0(1:2),'interpreter','latex','string','\fontsize{12}{0}\selectfont$t$\fontsize{8}{0}\selectfont$d$');
but this resulted in placing the text onto the figure I have, not where the static-text box was placed. See the picture below. How can I place 't_d' where the statictext was placed, to the left of 11.857?
pic01.bmp

Products


Release

R14SP1

Community Treasure Hunt

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

Start Hunting!