Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Square root symbol label in Matlab

Tags:

matlab

How to get the square root sign inside a legend? I tried \surd, but did not consider all my expression below this symbol. \sqrt and \square do not work at all.

m=[2 4.8 7 9.1 11.5 15 20 29 59 90 130 190 250];
size(Te);
s=0:0.02:0.246;
size(s);
E0=0.1;
t0=0.05;
f=0.01;
I0=2e9;
I1=1e14.*[m./(3680.*(1.08)^(1./3))].^(1.5);
hold on
Ifitting=I0./(sqrt(2.*pi).*f).*exp(-[s-t0].^2./(2.*f.^2));
[ay,h1,h2]=plotyy(s.*1e6,I1,s.*1e6,Ifitting,'loglog','plot')
axes(ay(1)); ylabel(' Intensity');
axes(ay(2)); ylabel('Intensity [fitting]');
set(ay(1),'Ylim',[0 2e12])
set(ay(2),'Ylim',[0 2e12])
xlabel('time [\mu m]','FontSize',16,'FontName','Times-Roman');
set([h1],'marker','o')
set([h2],'marker','o')
b=legend([h1 h2], ['I=10^{14}'],['I_{fitting}=I_0$$\sqrt{(2)\sigma}$$e^{\sigma}']);  
set(b,'Interpreter','latex','fontsize',24)
like image 530
user3271929 Avatar asked Feb 18 '14 18:02

user3271929


2 Answers

you can try this:

plot(sqrt(1:10)); 
h = legend(['$$\sqrt{blah}$$'])
set(h,'Interpreter','latex','fontsize',24) 

enter image description here

like image 195
bla Avatar answered Oct 06 '22 00:10

bla


Create the legend with LaTeX-style text, and then set to 'latex' the 'interpreter' property of all children of the lenged that are of type 'text':

leg = legend('$\sqrt{x-1}$'); %// this will give a warning; ignore it
t = findobj('Parent',leg,'Type','text');
set(t,'Interpreter','latex')

It would be easier if legend accepted the 'interpreter' property directly (legend('$\sqrt{x-1}$','interpreter','latex')), but it doesn't, at least in R2010b. ... However, it seems to work if after the legend object has been created; see natan's answer.

like image 28
Luis Mendo Avatar answered Oct 06 '22 01:10

Luis Mendo