各行から最初の行を減算し、相対的な差を計算します。

各行から最初の行を減算し、相対的な差を計算します。

各行から最初の列を減算して、別の列から新しい列を作成しようとしています。次に、相対的な差を持つ別の列を作成します。

\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableread{
TotalDistance
35089
35182
35410
35523
35694
35789
35895
35984
36006
36068
}{\mytable}
\pgfplotstabletypeset[
    columns={TotalDistance,LocalDistance},
    create on use/LocalDistance/.style={
        create col/expr={\thisrow{TotalDistance} - 35089},
    },
    create on use/DifferenceDistance/.style={
        create col/expr={\thisrow{LocalDistance} - \prevrow{LocalDistance}},
    },
    ]{\mytable}
\end{document}

私の目標は以下のとおりです:

  TD  | LD  | DD
------+-----+----
35089 |   0 |   0
35182 |  93 |  93
35410 | 321 | 228
35523 | 434 | 113
35694 | 605 | 171
35789 | 700 |  95
35895 | 806 | 106
35984 | 895 |  89
36006 | 917 |  22
36068 | 979 |  62

これまでの問題は次のとおりです。

  1. ハードコードを避け35089、代わりに最初のセルから読み取るにはどうすればよいですか?
  2. エラーが発生します不明な関数 `LocalDistance__column_not_found'列 DifferenceDistance をタイプセットしようとすると、列 LocalDistance は問題なく作成されるにもかかわらず、

答え1

  1. 最初のセルの値は で読み取ることができます\pgfplotstablegetelem{<row>}{<col>}\of\mytable。戻り値は に書き込まれます\pgfplotsretval

  2. 提案された打楽器\pgfplotstablecreatecolの代わりにを使用して\pgfplotstabletypesetテーブルに列を追加する例を次に示します。

ここに画像の説明を入力してください

\documentclass{article}
\usepackage{pgfplotstable}

\begin{document}

\pgfplotstableread{
TotalDistance
35089
35182
35410
35523
35694
35789
35895
35984
36006
36068
}{\mytable}

% read the first cell value -> \pgfplotsretval
\pgfplotstablegetelem{0}{TotalDistance}\of\mytable

% add column LocalDistance
\pgfplotstablecreatecol
    [expr={\thisrow{TotalDistance} - \pgfplotsretval}]
    {LocalDistance}{\mytable}

% add column DifferenceDistance
\pgfplotstablecreatecol
    [expr={\thisrow{LocalDistance} - \prevrow{LocalDistance}}]
    {DifferenceDistance}{\mytable}

% typeset the table
\pgfplotstabletypeset
    [columns={TotalDistance,LocalDistance,DifferenceDistance}]
    {\mytable}

\end{document}

関連情報