I have a pgfplotstable that contains coordinates of points for example
\pgfplotstableread{
t x
0.0 0.0
1.0 2.0
3.0 5.0
6.0 10.0
11.0 12.0
}\points
I want to create another table with the slopes around the second and the fourth points. I used the following code to compute the slopes:
\foreach \j in {1,3} {% using foreach because in reality I am using a very large table
\pgfmathsetmacro{\jb}{\j + 1}% The index of the previous point
\pgfmathsetmacro{\ja}{\j - 1}% The index of the next point
\pgfplotstablegetelem{\j}{t}\of\loadedtable% The value of t in the current point
\pgfmathsetmacro{\t}{\pgfplotsretval}% Set the value of t in the variable \t
\pgfplotstablegetelem{\ja}{t}\of\loadedtable% The value of t of the previous point
\pgfmathsetmacro{\ta}{\pgfplotsretval}% Set the value in the variable \ta
\pgfplotstablegetelem{\ja}{x}\of\loadedtable% The value of x of the previous point
\pgfmathsetmacro{\xa}{\pgfplotsretval}% Set the value in the variable \xa
% Doing the same thing for the next point
\pgfplotstablegetelem{\jb}{t}\of\loadedtable%
\pgfmathsetmacro{\tb}{\pgfplotsretval}%
\pgfplotstablegetelem{\jb}{x}\of\loadedtable%
\pgfmathsetmacro{\xb}{\pgfplotsretval}%
% Computing the slope
\pgfmathsetmacro{\v}{(\xb - \xa)/(\tb - \ta)}%
}
However it does not work very good and I don't know how to use it to create a new table with slopes. My aim is to have a way to store the values of t (time) and v (slope) in a new table. Can anyone help me to do that correctly?