An error message such as
Argument of \@caption has an extra }
usually means that a command in the argument of \caption
needs protection. In this case the command is surely \MSE
. Thus
\caption{A caption \protect\MSE{img1(illusion)}{\BilineaireA}}
might solve the problem.
However, in this particular application \protect
is not sufficient. We need something that contains the value we need, so a different road can be taken. Define a similar \MSEset
macro, that takes also an optional argument (default value \MSEresult
:
\begin{filecontents*}{data.csv}
Images,Infos,Bayer,BilineaireA,BilineaireB,TeinteA,TeinteB,ContourA,ContourB,Forme
img1(illusion),Temps (en ms),0,4,5,7,6,6,7,442
img1(illusion),Erreur MSE,152.44,34.44,34.44,24.04,24.04,24.06,25.99,32.90
img1(illusion),Erreur DeltaE,17.70,4.92,4.92,4.58,4.58,4.39,4.30,5.24
img1(illusion),Erreur PSNR (en dB),26.30,32.76,32.76,34.32,34.32,34.32,33.98,32.96
\end{filecontents*}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{csvsimple}
\newcommand{\MSE}[2]{%
\csvreader[ head to column names,%
before filter=\ifthenelse{ \equal{\Images}{#1} }{%
\ifthenelse{ \equal{\Infos}{Erreur MSE} }{\csvfilteraccept}{\csvfilterreject}%
}{\csvfilterreject}]%
{data.csv}{}{#2}%
}
\newcommand{\MSEset}[3][\MSEresult]{%
\csvreader[ head to column names,%
before filter=\ifthenelse{ \equal{\Images}{#2} }{%
\ifthenelse{ \equal{\Infos}{Erreur MSE} }{\csvfilteraccept}{\csvfilterreject}%
}{\csvfilterreject}]%
{data.csv}{}{\xdef#1{#3}}%
}
\newbox{\remibox}
\begin{document}
\listoffigures
\begin{figure}
\centering
My Image
\MSEset{img1(illusion)}{\BilineaireA}
\caption{A caption \MSEresult}
\end{figure}
\end{document}
You set the macro before typing the \caption
and use \result
to stand for the value. You can also say
\MSEset[\MSEresultA]{img1(illusion)}{\BilineaireA}
or any control sequence you want if you need more than one of these numbers. Take care of using control sequence names that are not used elsewhere (a common prefix such as MSE
should do).
This will print the correct value also in the List of Figures, should you need it.
To get a linear regression line for data from a data file, use
\addplot [no markers] table [y={create col/linear regression={y=<column name>}}] {<file name>};

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots, pgfplotstable}
\usepackage{filecontents}
\begin{filecontents}{table.dat}
x y
0 1
100 3
150 2
200 5
300 6
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=middle,
axis y line=middle,
enlarge y limits=true,
width=15cm, height=8cm, % size of the image
grid = major,
grid style={dashed, gray!30},
ylabel=steps,
xlabel=$n$,
legend style={at={(0.1,-0.1)}, anchor=north}
]
\addplot[only marks] table {table.dat};
\addplot [no markers, thick, red] table [y={create col/linear regression={y=y}}] {table.dat};
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
If you need to plot data from files, I think you'll be much happier if you use PGFPlots instead of the native
plot
functionality of TikZ. Here's a very simple example of plotting your example data to get you started.PGFPlots is very customizable, you can tweak virtually every aspect of your plots, and it's much more user-friendly than if you tried to knit everything yourself.