
를 사용하여 읽어야 하는 데이터 파일 수가 적당히 많으며 \pgfplotstablesort
, 각 경우에 읽은 데이터는 나중에 플롯에서 사용할 수 있도록 매크로에 할당되어야 합니다. 파일 이름은 예측 가능한 패턴을 따르므로 데이터를 읽고 이를 파일 이름과 관련된 이름의 매크로에 할당하는 매크로를 만들고 싶습니다. 지금까지 나는 이것으로 작업해왔습니다:
\def\readdata#1#2#3#4{
\def\filenamepattern##1{#1}
\pgfplotstablesort{\csname #4himu\endcsname}{\filenamepattern{#3}}
\pgfplotstablesort{\csname #4lomu\endcsname}{\filenamepattern{#2}}
% other stuff
}
\readdata{testfile#1.dat}{10}{50}{testdata}
물론 첫 번째 인수 \pgfplotstablesort
를 처리할 수 없기 때문에 컴파일되지 않습니다. PDFLaTeX는 으로 시작 하고 종료되지 않는 \csname
많은 오류를 뱉어냅니다 . Missing \begin{document}
저는 그것이 문제의 근본 원인이라는 것을 알고 있습니다. 왜냐하면 해당 매크로 이름을 수동으로 입력하면
\def\readdata#1#2#3#4{
\def\filenamepattern##1{#1}
\pgfplotstablesort{\testdatahimu}{\filenamepattern{#3}}
\pgfplotstablesort{\testdatalomu}{\filenamepattern{#2}}
% other stuff
}
잘 작동합니다.
이제 나는 \expandafter
그것이 \csname...\endcsname
이전에 확장 될 것이라고 생각하면서 다음을 시도합니다 \pgfplotstablesort
.
\def\readdata#1#2#3#4{
\def\filenamepattern##1{#1}
\expandafter\pgfplotstablesort{\csname #4himu\endcsname}{\filenamepattern{#3}}
\expandafter\pgfplotstablesort{\csname #4lomu\endcsname}{\filenamepattern{#2}}
% other stuff
}
하지만 그것은 아무런 변화를 가져오지 않습니다. 나는 이것이 의 정의와 관련이 있다고 생각합니다 \pgfplotstablesort
. 아마도 선택적 인수를 취할 수 있는 방법일 것입니다. 그러나 그것을 알아내려고 노력할 때 길을 잃습니다.
내가 하려는 일을 작동시킬 수 있는 방법이 있는지, 그리고 \expandafter
내가 시도한 것이 왜 실패했는지 설명할 수 있는 사람이 있습니까? 나는 이것을 실제로 플로팅을 위해 내 데이터 파일을 로드할 수 있는 것 외에도 매크로 확장을 더 잘 이해할 수 있는 기회로 사용하고 싶습니다.
MWE 완료:
\documentclass{article}
\usepackage{filecontents,pgfplots,pgfplotstable}
\begin{filecontents*}{testfile10.dat}
pT Y mu2 lomean lostddev loerrbound nlomean nlostddev nloerrbound
0.35 2.2 10 2.8920929e+00 0 1.7555822e-04 1.1823986e+00 1.6578794e-01 6.7619291e-02
\end{filecontents*}
\begin{filecontents*}{testfile50.dat}
pT Y mu2 lomean lostddev loerrbound nlomean nlostddev nloerrbound
0.35 2.2 10 2.8920929e+00 0 1.7555822e-04 1.1823986e+00 1.6578794e-01 6.7619291e-02
\end{filecontents*}
\def\readdata#1#2#3#4{
\def\filenamepattern##1{#1}
\pgfplotstablesort{\csname #4himu\endcsname}{\filenamepattern{#3}}
\pgfplotstablesort{\csname #4lomu\endcsname}{\filenamepattern{#2}}
% other stuff
}
\readdata{testfile#1.dat}{10}{50}{testdata}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ymode=log]
\addplot table[x=pT,y=lomean] {\testdatahimu};
\addplot table[x=pT,y=lomean] {\testdatalomu};
\end{axis}
\end{tikzpicture}
\end{document}
답변1
내가 생각 하기엔
\newcommand\readdata[4]{%
\def\filenamepattern##1{#1}%
\expandafter\pgfplotstablesort\csname #4himu\endcsname{\filenamepattern{#3}}%
\expandafter\pgfplotstablesort\csname #4lomu\endcsname{\filenamepattern{#2}}%
% other stuff
}
\readdata{testfile#1.dat}{10}{50}{testdata}
\pgfplotstablesort
매크로 이름이 표시되므로 그렇게 할 것입니다 .
왜 일을 안 했어 \expandafter
? 교정기를 확장하려고 했기 때문입니다. 교정기가 필요한 경우(그렇지 않다고 생각함)
\expandafter\pgfplotstablesort\expandafter{\csname #4himu\endcsname}{\filenamepattern{#3}}%
의 역할이 확실하지 않지만 \filenamepattern
매크로는 귀하의 것입니다.