1

I hope you can help me. I want to create a variable with name 'x' with the values of the column with header 'x' of the array .csv file called 'data' (please see below). Could you help me do it?

.csv array semicolon separed:

data ='x';'y';'z'\\
      1;2;3\\
      4;5;6\\
      7;8;9

I would like to obtain: x = column vector [1;4;7]

I want to do this in a TikZ environment.

Another question: If I were to evaluate the value of the 3rd element of 'x', how could I do it?

I would like to get the value x(3) = 7.

Also, I would like to obtain the minimum value of the column 1 of the vector 'x', how can I do that?

Thanks in advance.

1 Answer 1

1

Here, I use readarray to import the data and listofitems to parse it.

\begin{filecontents*}[overwrite]{data.csv}
data ='x';'ycol';'z'\\
      1;2;3\\
      4;5;6\\
      7;8;9
\end{filecontents*}
\documentclass{article}
\usepackage{readarray,listofitems}
\newcommand\arrayelement[2]{%
  \def\tmpA{#1}%
  \foreachitem\z\in\dataarray[1]{%
    \edef\tmpB{\dataarray[1,\zcnt,2]}%
    \ifnum\pdfstrcmp{\tmpA}{\tmpB} = 0 \dataarray[#2+1,\zcnt]\fi
  }%
}
\begin{document}
\readdef{data.csv}\mydata
\setsepchar{\\/;/'}
\readlist*\dataarray{\mydata}

\arrayelement{x}{2},
\arrayelement{ycol}{1},
\arrayelement{z}{3}.
\end{document}

enter image description here

1
  • Thank you very much!
    – el_maxx
    Commented Sep 2, 2022 at 12:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .