What is the syntax for subscripts in a plot text box?

I am working on a code to plot a function with a title and an annotation below the graph. So far everything is working smoothly -except- the subscript syntax [ '_' ] is only working in the title and not my annotation text box. i.e. EIF_2 is subscripted, but E_0, k_1, and k_{-1} is not. I'm at a loss. Any suggestions?
A few notes on my code: The annotation text box contains 3 lines of text and "prints" parameter values defined elsewhere in my .m file.
------------------------------------------------------------------------------
Here's the plotting portion of my code:
%Plot the solution
fig1=figure; %Create a new figure
h_axes = axes('parent',fig1,'position',[.1 .3 .8 .6]);
plot(h_axes,t,x(:,1),'r',t,x(:,2),'b',t,x(:,3),'g',t,x(:,4),'m',t,x(:,5),'--r',t,x(:,6),'--b',t,x(:,7),'--g',t,x(:,8),'--m',t,x(:,10),'k', t,x(:,11),'--k')
title(['EIF_2 Subfunction Model 4 -- (Initial PKR = ',num2str(x11),')'])
h_text=uicontrol('style','text','parent',fig1,'units','normalized','position',[.1 .05 .8 .1]);
set(h_text,'string',{[
'Initial Conditions: E_0 = ' ,num2str(E0),';'];
['Forward Parameters: k_1 = ',num2str(k1), ';'];
['Reverse Parameters: k_{-1} = ',num2str(k_1),';'];
})
xlabel('time')
ylabel('State Variable Values')
leg=legend('E_T', 'E_D', 'E_P', 'E_B','C_1','C_2','C_3','C_4','M','Pk','Location','NorthEastOutside');
-------------------------------------------------------------------------------
Any suggestions would be greatly appreciated!
-- Laura

 Accepted Answer

UICONTROL objects do not support LaTeX or TeX markup. If you search "uicontrol tex" or "uicontrol latex" on Google, you will see links to several possible workarounds that people have found. These sometimes involve other functions that have been posted to the file exchange or other hacks with different types of graphics objects.
The easiest way to get TeX markup in your figure is just to use the TEXT command instead of the UICONTROL command. Be aware that a text object is the child of the axes, so it should be positioned based on the axes units.

5 Comments

Does the TEXT command work if I want the annotation in a text box beneath the actual graph (but within the figure)? The annotation I included in my submission above is quite a bit shorter than my actual annotation which would disrupt the clarity of the figure if it was included on the graph. Thanks!
Yes, it does work outside the bounds of the axes. However, it's difficult to position this way because you still have to specify the location in terms of the axes units. For example, if the text is below the axes, it's y location should be less than the minimum value on the y-axis and defined in units of that axis (rather than figure units).
I haven't played with UIBUTTON from File Exchange, but it seems to be designed for this type of situation.
Okay - I'll look into that. Thanks again!
With some minor tweaking to my code it worked like a charm!

Sign in to comment.

More Answers (0)

Asked:

on 9 Jul 2013

Community Treasure Hunt

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

Start Hunting!