0

I want to calculate the hash value of several columns and store the unique value in another column using pgfplotstable.

In my shown MWE I just try this approach with two columns X & Y. I want to combine them (just concatenate the strings) and calculate the hash value.

Unfortunately, the function \pgfplotstablegetelem{\pgfplotstablerow}{X}\of\mydata is not working for me.

I get the error message:

Package pgfplots Error: Sorry, row `2' does not exist in table <inline_table>.

So this is not working... Can anyone help me? :)

MWE

\documentclass[10pt,a4paper]{article}
\usepackage{pgfplotstable}
\usepackage{xstring}
\pgfplotsset{compat=newest}

\newcommand{\calcHash}[1]{ \noexpand\StrLeft{\pdfmdfivesum{#1}}{3} }

\pgfplotstableread[]{ X Y 1 a 2 b 5 c }\mydata

\begin{document} \pgfplotstablecreatecol[ create col/assign/.code={ %\pgfplotstablegetelem{\pgfplotstablerow}{X}\of\mydata %\pgfmathsetmacro\xValue{\pgfplotsretval} %\pgfplotstablegetelem{\pgfplotstablerow}{Y}\of\mydata %\pgfmathsetmacro\yValue{\pgfplotsretval} \edef\myHash{\noexpand\calcHash{abc}} % I want to replace "abc" with "\xValue\yValue" \pgfkeyslet{/pgfplots/table/create col/next content}\myHash }]{ID}{\mydata} \pgfplotstablegetrowsof{\mydata} \pgfmathtruncatemacro\myDataRows{\pgfplotsretval-1}

\pgfplotstabletypeset[string type]{\mydata} \end{document}

RESULT

Result

PascalS
  • 826

1 Answers1

2

You can simply use \thisrow{<column>} instead:

\documentclass[10pt,a4paper]{article}
\usepackage{pgfplotstable}
\usepackage{xstring}
\pgfplotsset{compat=newest}

\newcommand{\calcHash}[1]{ \noexpand\StrLeft{\pdfmdfivesum{#1}}{3} }

\pgfplotstableread[]{ X Y 1 a 2 b 5 c }\mydata

\begin{document} \pgfplotstablecreatecol[ create col/assign/.code={ \edef\myHash{\pdfmdfivesum{\thisrow{X}\thisrow{Y}}}% \pgfkeyslet{/pgfplots/table/create col/next content}\myHash }]{ID}{\mydata} \pgfplotstablegetrowsof{\mydata} \pgfmathtruncatemacro\myDataRows{\pgfplotsretval-1}

\pgfplotstabletypeset[string type]{\mydata} \end{document}

Skillmon
  • 60,462