Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

LaTex in static text field of a GUI using Matlab GUIDE

1,183 views
Skip to first unread message

Aaronne

unread,
Jun 25, 2012, 7:31:07 AM6/25/12
to
Hi all,

I am trying to insert a LaTeX symbol in a label in a GUI.
I have created the GUI in GUIDE, but cannot seem to get symbols like alpha, phi etc in a static text field. Should this be done in the property inspector or in the .m file?

I have tried a solution as:
http://www.mathworks.co.uk/support/solutions/en/data/1-1VE03X/index.html?product=ML&solution=1-1VE03X

But it just gives a mess of everything in the GUI. Any ideas?

Thank you and best regards,
Aaronne.

matt dash

unread,
Jun 25, 2012, 11:29:08 AM6/25/12
to
"Aaronne" wrote in message <js9i5r$gq4$1...@newscl01ah.mathworks.com>...
As the solution link is trying to suggest, you can't display latex on a uicontrol. Instead you need to make an invisible axes and put a text object in the axes. (make the axes in GUIDE and the text object in the m file)

Aaronne

unread,
Jun 25, 2012, 12:02:06 PM6/25/12
to
Hi Matt,

Thanks for your reply, but I still not get it.

I have put the codes in right place of my GUI_figure.m file.

Then I also create a 'static text' object in the GUIDE .fig, and change the 'tag' to something start with 'latex_'. However, nothing happens but the added codes just give a mess of the whole GUI.

Or do you mean that we need to add an 'axes object' in the GUIDE .fig?

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
% 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

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

matt dash

unread,
Jun 25, 2012, 12:19:07 PM6/25/12
to
"Aaronne" wrote in message <jsa21u$22s$1...@newscl01ah.mathworks.com>...
> Hi Matt,
>
> Thanks for your reply, but I still not get it.
>
> I have put the codes in right place of my GUI_figure.m file.
>
> Then I also create a 'static text' object in the GUIDE .fig, and change the 'tag' to something start with 'latex_'. However, nothing happens but the added codes just give a mess of the whole GUI.
>
> Or do you mean that we need to add an 'axes object' in the GUIDE .fig?
>

Yes. You need to make an axes object instead of a static text uicontrol object. The tag has nothing to do with it... that's just a poorly chosen example in the link.

Aaronne

unread,
Jun 25, 2012, 12:31:06 PM6/25/12
to
Quite confusing now...

I thought the 'tag' is used to find the object we need to give latex string for the text.

So, currently, I put an 'axes' object on my GUI using GUIDE. Then may I ask what I need to do?

How can I get a 'pi' show up in the 'axes' object? Thanks so much if you can give me some tips.


Aaronne.

matt dash

unread,
Jun 25, 2012, 2:12:06 PM6/25/12
to
"Aaronne" wrote in message <jsa3oa$a7l$1...@newscl01ah.mathworks.com>...
Just look at what the code you posted is doing. It finds each uicontrol with the "latex" tag. Then it deletes it (actually does this towards the end), and replaces it with an invisible axes that contains a text object that displays the desired text. Here is an example contrasting the two approaches:

f=figure
%uicontrols can't display latex:
u=uicontrol('units','pixels','position',[20 200 200 24],...
'style','text','string','I can''t display \pi',...
'horiz','left',...
'backgroundcolor',get(f,'color'));

%but text objects can:
axes('units','pixels','position',[20 100 200 24],'visible','off')
text(0,0.5,'I can display $\pi$','interpreter','latex',...
'horiz','left','vert','middle')

Benjamin Windheim

unread,
Jan 26, 2016, 1:57:11 AM1/26/16
to
I had the same Problem. But I solved it. You need to start the mathematical input mode. You just put an static text box to the figure an set the Tag so it starts with "latex_". Then set the string to "$\pi$" or an other Latex string you want to display. You just need this: $...$
0 new messages