I generate a plot in MATLAB using the code below (MWE):
x = [1:100];
y = x.^0.5;
[hLine1]=semilogx(x,y);
hleg1 = legend(sprintf('%.4f',0.4334));
set(get(hleg1,'title'),'string','test');
set(hleg1, 'EdgeColor', 'w');
set(hleg1,'Location','NorthWest');

(The legend title seems to not be factored in when using set location Northwest but that is a question for the MATLAB S.E...)
I slide the legend to a different position in the plot and then convert it to a .tikz.
It is compiled in latex with:
\documentclass[11pt,a4paper]{report}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\centering
\input{fig1.tikz}
\caption{...}
\end{figure}
\end{document}
This creates the following plot:

the legend's title has disappeared. I can not find it anywhere in the .tikz created file.
So this may be a glitch with matlab2tikz but any workaround? Thanks.
Edit: So this is probably a matlab2tikz issue. Leaving that bit, I managed to get a legend title in tikz using some code I found. But it does not center the title over the line + text, just the text. Full MWE to show the problem:
\documentclass{article}
\usepackage{pgfplots}
% and optionally (as of Pgfplots 1.3):
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\newlength\figureheight
\newlength\figurewidth
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
width=4.52083333333333in,
height=3.565625in,
scale only axis,
xmode=log,
xmin=1,
xmax=100,
xminorticks=true,
ymin=1,
ymax=10,
legend style={at={(0.03,0.97)},anchor=north west,draw=none,legend cell align=left}
]
\addlegendimage{legend image code/.code=} %These two lines add the title to the legend
\addlegendentry{example} %But I would like it centered over the line and the text
\addplot [color=blue,solid]
table[row sep=crcr]{1 1\\
2 1.4142135623731\\
3 1.73205080756888\\
4 2\\
5 2.23606797749979\\
6 2.44948974278318\\
7 2.64575131106459\\
8 2.82842712474619\\
9 3\\
10 3.16227766016838\\
};
\addlegendentry{0.4334};
\end{axis}
\end{tikzpicture}%
\end{document}

How could I center the legend title? Thanks
pgfplotsoffers atitlefor the entire figure (but none for the legend). – Christian Feuersänger Apr 05 '14 at 18:16.tikz,.tex, doesn't matter..tikzis used a lot to indicate that it just contains TikZ/pgfplotscode, but it just a matter of taste. @Steve: Ifmatlab2tikzdoesn't pick up the legend title, as it appears, then you should add a feature request on GitHub as Christian says. If you would like to add a title manually, see e.g. http://tex.stackexchange.com/questions/2311/ – Torbjørn T. Apr 05 '14 at 21:49pgfplotsdoes not have a standard title feature for the legend this was not so easy formatlab2tikzto impliment. – Steve Hatcher Apr 06 '14 at 05:53\addlegendimage{legend image code/.code=} \addlegendentry{title}. The only problem with this method is it does not center the title over the line + text annotations under it, it justifies it with the text. Trying not to ask a second question but I think this falls into kind of the same category of what I originally wanted. I will edit my original question for this. – Steve Hatcher Apr 06 '14 at 05:55\hspace{-0.5cm}example. – Torbjørn T. Apr 06 '14 at 09:16