The latex code below does not compile. This is due to \foreach and the function \getcolor.
Does anybody know, how I can use the variable set by \foreach in a function.
Find below the code
\documentclass{article}
\usepackage{pgfplots}
\usepackage[debug,pdftex]{insdljs}
\usetikzlibrary{patterns}
\def\Colorarray{{1}{blue}{2}{red}{3}{orange}{4}{yellow}}
\def\getcolor#1{\expandafter\xgetcolor\Colorarray{#1}{}test{#1}}
\def\xgetcolor#1#2#3test#4{\ifnum#4=#1 #2\else\xgetcolor#3test{#4}\fi}
\pgfkeys{/pgf/number format/.cd, set decimal separator={,{\!}}, set thousands separator={}}
\newcommand{\doAxeX}{
\begin{axis}[ xmin=0,xmax=1800, %ymin=0, ymax=250,
axis y line*=right, axis x line*=bottom, axis x line=none,
y tick label style={font=\tiny, color=green},
ylabel style={at={(1.3,0.5)},anchor=center},
ylabel={\color{green}$Load$}]
\addplot[smooth,green] table[x index=0,y index=5] {S1SearchArticle.dat};
\end{axis}
}
\begin{document}
\begin{tikzpicture}[scale=1]
\doAxeX
\begin{axis}[title={Evolution du temps page pour le scénario}, grid=major, axis x line=bottom, axis y line=left,
xlabel={Durée du test}, ylabel={Page time(s)},
x tick label style={font=\tiny, rotate=35},
y tick label style={font=\tiny},
x label style={font=\small},
y label style={font=\small},
legend entries={\xarrayget{Page}{#1}},legend style={font=\tiny, at={(1.5,1)}}]
\node [opacity=0.3] at (axis description cs:0.17,0.9) {\includegraphics[scale=0.5]{image001.png}};
\foreach \c in {1,2,...,4} {
\addplot[smooth,\getcolor{\c}] table[x index=0,y index=\c] {S1SearchArticle.dat};
\end{axis}
\end{tikzpicture}
\end{document}


`, they'll be marked as code, as can be seen in my edit. You can also highlight the code and click the "code" button (with "{}" on it). – Joseph Wright♦ Jul 13 '12 at 7:31plot cycle listfeature of PGFPlots, instead of using a collection of arrays and macros. See this answer for an example: tex.stackexchange.com/a/50878/2552 – Jake Jul 13 '12 at 7:42foreach. – kgr Jul 13 '12 at 17:29