# How to create legend in loop using parameters from text file with PGFPlots?

I have parameter in a text file and I would like to create legend using those parameters. I have tried to read data with

\pgfplotstableread{param.txt}{\myparams}


and get specific parameter with

\pgfplotstablegetelem{0}{0}\of{\myparams}


and then set macro with

\pgfmathsetmacro\parA{\pgfplotsretval}


and the create legend entry with

\addlegendentry{\pgfmathprintnumber[precision=5,use comma]{\parA}}


I have tried to do this with \foreach command and simply copy-pasting but neither one has succeeded.

One entry consist of multiple different elements from table.

Do you mean something like ...

% create a dummy file with some values
\begin{filecontents}{param.txt}
0.1 0.2 0.3
0.4 0.5 0.6
\end{filecontents}
\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
% create a loop and specify some indices that can be found
% in the data file
\foreach \i/\j in {
0/0,
1/1,
0/2%
}{
% read the element in the data table and store it in \param'
\pgfplotstablegetelem{\i}{\j}\of{\myparams}
\pgfmathsetmacro{\param}{\pgfplotsretval}
% now create the plot and the corresponding legend entry
`