I am using the "functions" \findmin and findmax from here quite much to dynamical format and set plots from CSV data I read in.
In the same vein, I want a function \findFirstNonZeroIndex, which returns the integer index of the first element which is non-zero in a specified column. Since all my data are non-negative integers, non-zero is equal to being greater than 0.
Since the indices in pgfplotstable start with 0, how do I add 1 to this number?
From the pgfplotstable manuel, the iflessthan command seems capable of doing what I want:
\pgfplotstablesort[sort key={#2},sort cmp={
iflessthan/.code args={#1#2#3#4}{%
% here comes your code
}%
}]{\result}{\datatable}
Some example data:
\begin{filecontents}{table.dat}
x y
1 0
2 0
3 30
4 0
5 50
\end{filecontents}
If possible, I do only want to use the column =y=index[1] and get something like \findFirstNonZeroIndex{\inputtable}{\outputvalue}. In this example, \outputvalue should be 3.
If it is easier, up to now I only use integer values in column y sorted ascending. So there would not be a 0 in row x=4.
I just do not know enough on how to get started. Any help would be appreciated.
Edit
Steven B. Segletes just answered my question with the help of package readarray.
Out of curiosity, is there a solution using the pgf framework?
\ifdim\cell pt>0pt, but if they're larger than that you'll need to use thefpulibrary. – Jake Feb 24 '15 at 15:14