각 행에서 첫 번째 행을 빼고 상대적인 차이를 계산합니다.

각 행에서 첫 번째 행을 빼고 상대적인 차이를 계산합니다.

각 행에서 첫 번째 행을 빼서 다른 행에서 새 열을 만들려고 합니다. 그런 다음 상대적인 차이가 있는 다른 열을 만들고 싶습니다.

\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'LocalDistance 열이 문제 없이 생성되더라도 DifferenceDistance 열을 조판하려고 할 때.

답변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}

관련 정보