4

What I want to do is creating automatically the filenames of the datafiles inside a foreachloop in tikz. Maybe it's better to show a minimal example first:

\documentclass{standalone}
\usepackage{tikz,pgfplots,pgfplotstable}
\pgfplotstableset{%
    col sep=semicolon,
    x index=0,
    y index=1,
}
\usetikzlibrary{fpu}
\usepackage{filecontents}

\begin{filecontents}{(TA0.04)(T0.08).txt}
1;1
2;2
3;3
\end{filecontents}

\begin{filecontents}{(TA0.04)(T0.09).txt}
2;1
3;2
5;3
\end{filecontents}

\begin{filecontents}{(TA0.04)(T0.10).txt}
4;1
5;2
8;3
\end{filecontents}


\begin{document}

\begin{tikzpicture}
\def\TA{0.04}
\begin{axis}[xlabel=$x$, ylabel=$y$]
    \foreach \A in {0.04,0.05,0.06} {
        \pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}
        \pgfmathsetmacro{\T}{\TA+\A}
        \pgfmathroundtozerofill{\T}
        \addplot table {(TA\TA)(T\T).txt};
    }
\end{axis} 
\end{tikzpicture}

\end{document}

Inside this little tikz picture I want to do the following (and I have to do this for quite a big set of datafiles and different starting values).

  • First I want to define a starting value for \TA which I've done with \def...
  • Given the list of looping numbers i want to calculate for each loop a now variable \T which represents the sum of \TA and the current looping variable \A
  • Now, given this three numbers I want to load my data from my datafile (see preamble for filenames)

And here is my problem...

When the sum is equal to 0.10 I get the error:

... Could not read table file '(TA0.04)(T0.1).txt'. ...

because the value of \T is 0.1 and not 0.10.

Each numbers in my filenames have exactly two digits, but sometimes the last one is a zero as shown above. I tried to fix this with \pgfmathroundtozerofill{\T} but it does not work.

Has anybody an idea how I can fix this problem?? How can I fix the number of digits or add this zeros to the number???

P.S. Title seems to be the same than number formatting in foreach statement of tikz, but this question didn't helped me. Therefor I started a now one.

3

You almost had it, you only have to use \pgfmathresult instead of \T in your \addplot command. That's because \pgfmathroundtozerofill doesn't alter the contents of \T, but rather saves the result in \pgfmathresult.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.