我有一个.csv 文件,其中我通过读取 Y 变量的最大值来操纵该值并尝试为操纵的 Ymax 找到一个额外的 X 值。
这是代码。
\csvreader[head to column names, filter test = \ifnumequal{\thecsvinputline}{3},]{csv/IGS2a_ac.csv}{\YRe}{\pgfmathsetmacro{\val}{\YRe}}\pgfmathparse{(\val/sqrt(2))}\xdef\d{\pgfmathresult}
\pgfmathparse{\d+20}\xdef\du{\pgfmathresult}
\pgfmathparse{\d-20}\xdef\dl{\pgfmathresult}
% Read the freq that matches -3db Mag value
\csvreader[head to column names, filter test = \if{\YRe>\dl and \YRe<\du}\fi,]{csv/IGS2a_ac.csv}{\Freq}{\pgfmathsetmacro{\val}{\Freq}}\pgfmathparse{\val}\xdef\fd{\pgfmathresult}
.csv文件中对应的内容是
Freq YRe
10 115.8357654
15.13561248 115.8357654
22.90867653 115.8357654
34.67368505 115.8357653
52.48074602 115.835765
79.43282347 115.8357644
120.2264435 115.8357631
181.9700859 115.8357601
275.4228703 115.8357531
416.8693835 115.8357372
630.9573445 115.8357006
954.992586 115.8356169
1445.439771 115.8354252
2187.761624 115.834986
3311.311215 115.8339798
5011.872336 115.8316749
7585.77575 115.8263949
11481.53621 115.814301
17378.00829 115.7866049
26302.67992 115.7232068
39810.71706 115.5782316
60255.95861 115.2474777
91201.08394 114.4968532
138038.4265 112.8135848
208929.6131 109.1379117
316227.766 101.5575321
478630.0923 87.61611542
724435.9601 66.65387878
1096478.196 43.05409574
1659586.907 23.76990366
2511886.432 11.72902177
3801893.963 5.425717497
因此,第一个 csvreader cmd 给我 \d = 115.83/1.414 = 81.91,我想使用这个 81.91 值来计算 81.91+- 内的 X 值。但我最终得到了不同的答案,这是不正确的。
有人能在这方面帮助我吗?
答案1
\csvreader[head to column names, filter test = \ifnumequal{\thecsvinputline}{3},]{csv/IGS2a_ac.csv}{\YRe}{\pgfmathsetmacro{\val}{\YRe}}\pgfmathparse{(\val/sqrt(2))}\edef\d{\pgfmathresult}
% Initially step coursely to find the row
\xdef\ix{25}
\pgfmathparse{\ix+1}\xdef\iy{\pgfmathresult}
% Roughly choose the \thecsvinputline from 25 and read the \YRe value to begin the search
\csvreader[head to column names, filter test = \ifnumequal{\thecsvinputline}{\ix},]{csv/IGS2a_ac.csv}{\YRe}{\pgfmathsetmacro{\val}{\YRe}}\pgfmathparse{\val}\edef\da{\pgfmathresult}
% Convert the floating point number to dimensions to make comparision
\newdimen\dadim
\xdef\dadim{\da pt}
\newdimen\ddim
\xdef\ddim{\d pt}
\foreach \X [remember=\X as \LastX (initially \ix)] in {\iy,...,50}
{\ifdim\dadim>\ddim{
\csvreader[head to column names, filter test = \ifnumequal{\thecsvinputline}{\X},]{csv/IGS2a_ac.csv}{\YRe}{\pgfmathsetmacro{\val}{\YRe}}\pgfmathparse{\val}\xdef\da{\pgfmathresult}
\xdef\dadim{\da pt}
\csvreader[head to column names, filter test = \ifnumequal{\thecsvinputline}{\LastX},]{csv/IGS2a_ac.csv}{\YRe}{\pgfmathsetmacro{\val}{\YRe}}\pgfmathparse{\val}\xdef\db{\pgfmathresult}
}\else
{}
\fi
}
% Read the freq that matches -3db Mag value
\csvreader[head to column names, filter equal = {\YRe}{\da},]{csv/IGS2a_ac.csv}{\Freq}{\pgfmathsetmacro{\val}{\Freq}}\pgfmathparse{\val}\xdef\fa{\pgfmathresult}
\csvreader[head to column names, filter equal = {\YRe}{\db},]{csv/IGS2a_ac.csv}{\Freq}{\pgfmathsetmacro{\val}{\Freq}}\pgfmathparse{\val}\xdef\fb{\pgfmathresult}
使用线性插值法找出两个已知点之间的 Y 值。