Getting the (variable) number of columns per row with pgfplotstable?

I've already seen PGFplots and table with different number of elements in columns; but this is a slightly different question...

Consider the following MWE:

\documentclass{article} \usepackage{pgfplots} \usepackage{pgfplotstable} \usepackage{adjustbox}  \pgfplotstableread[   col sep=comma,   header=false, % columns/0/.style={string type}, % nowork here; on typeset ]{ c002,128,64,0.000119,-1,-1,0.000162,-1,-1,0.000494,-1,-1,0.001540,1,65,0.001906,0,1,0.002997,1,1,0.003341,0,65,0.004432,1,65,0.004797,0,1,0.005889,1,1,0.006253,0,65, c003,128,64,0.000166,-1,-1,0.000463,-1,-1,0.001546,1,65,0.001936,0,1,0.002981,1,1,0.003362,0,65,0.004437,1,65,0.004939,0,1,0.005918,1,1,0.006269,0,65, c004,128,64,0.000118,-1,-1,0.000161,-1,-1,0.000456,-1,-1,0.001518,1,65,0.001903,0,1,0.002973,1,1,0.003339,0,65,0.004410,1,65,0.004795,0,1,0.005866,1,1,0.006252,0,65, }\mytable  \pgfplotsset{%   compat=1.5.1, }  \pgfplotstablegetrowsof{\mytable} %Determine no. of rows \pgfmathtruncatemacro{\rows}{\pgfplotsretval} % pgfmathsetmacro float, this int \pgfmathtruncatemacro{\lastrow}{\rows-1}   \begin{document} \typeout{Rows: \rows} % 3.0  Test 1: \\ \newline   \foreach \r in {0,1,...,\lastrow}{   \pgfplotstablegetelem{\r}{[index]0}\of\mytable%   \edef\colzerotag{\pgfplotsretval}%   \pgfplotstablegetcolsof{\mytable} % how to get cols for this row???   \edef\numcolsstr{\pgfplotsretval}%   \noindent \r: \colzerotag\ - \numcolsstr \\ }   % just testing wide printout \begin{adjustbox}{width=\textwidth} \noindent\pgfplotstabletypeset[   columns/0/.style={string type},   font=\tiny, ]{\mytable} \end{adjustbox}  \end{document} 

The data has variable number of columns; I would like to avoid re-parsing the data and padding with null columns. Using the data verbatim as is, pdflatex fails with:

% ! Package pgfplots Error: input table '' has an unbalanced number of columns in row '2' (expected '37' cols; got '34'). Maybe the input table is corrupted? If you need unbalanced data, consider using 'nan' in empty cells (perhaps combined with 'unbounded coords=jump').

If you keep on pressing "Enter", the document will eventually compile, and this is the output (click for full size):

Getting the (variable) number of columns per row with pgfplotstable?

(The full table is rendered, just to confirm whether pgfplotstable interprets the data per row as I do - that is, "start from beginning, and keep going for as many data columns are available"; and it seems that is the case. There is an empty column appended, apparently because of existence of trailing comma , in the data)

So, basically, what I'd like to do is loop through each row, print the first column label as identifier, then print the number of columns in that row; the expected output would be:

0: c002 - 37 1: c003 - 37 2: c004 - 34 

Here just as a demo I use \pgfplotstablegetcolsof{\mytable} which will always use the first deduced number of columns for the table (so it always prints 37 regardless).

Is there a way I could achieve this only with pgfplotstable (possibly with an extra Latex package), without having to reparse the data?


Category: pgfplotstable Time: 2014-05-28 Views: 6

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.125 (s). 12 q(s)