Is it possible to determine the number of rows in a table read by pgfplotstableread{values.dat}\val
?
My setup is the following. I make experiments to see how a parameter affects a convergence curve. Results of such experiments look like
[results.dat]
n err_0 err_1 err_2 err_3
1024 0.1 0.2 0.15
2084 0.01 0.02 0.015
4096 0.001 0.002 0.0015
Parameters for each experiment is saved in a second table
[meta.dat]
0.5
2
3.7
11
Now I want to plot the results automatically (without knowing the number of experiments or the parameters)
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableread{results.dat}\values
\pgfplotstableread{meta.dat}\meta
\def\N{3} %change to automatic here
\begin{tikzpicture}
\begin{loglogaxis}
\foreach \i in {0,...,\N}{
%use elements from meta table here instead of \i
\edef\theLegend{\noexpand\addlegendentry{Generalized \i}}
\addplot table[x=n,y=err_\i]{\values};
\theLegend
}
\end{loglogaxis}
\end{tikzpicture}
\end{document}
The two points I have trouble with are marked with comments.
Best Answer
Using the pointers of percusse and the answer https://tex.stackexchange.com/a/36472/5737 I came to the following solution for my problem.