使用 pgplots/matlab2tikz 处理 nan

使用 pgplots/matlab2tikz 处理 nan

我目前正在使用 MATLAB 中带反馈的非线性模型开发一些模拟,其中存在一些不稳定的轨迹。

我想使用 matlab2tikz 导出它,这样我就可以在我的乳胶文档中获得与此完全一样的内容:

我想要的是

我遇到的主要问题是,当尝试将此 .tex 文件添加到我的文档时,它会产生一个错误,其中 pgfplots 不确定如何处理 nan。

\documentclass[tikz]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{grffile}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{patchplots}
\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}

\begin{axis}[%
width=6.028in,
height=4.754in,
at={(1.011in,0.642in)},
scale only axis,
unbounded coords=jump,
xmin=0,
xmax=30,
ymin=-60,
ymax=60,
axis background/.style={fill=white}
]
\addplot [color=red, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
nan nan\\
0   0\\
0   -0\\
nan nan\\
0   -0\\
0   0\\
0   -5.90295810358706e+20\\
0   0\\
};
\end{axis}
\end{tikzpicture}%
\end{document}

我事后尝试在 MATLAB 中使用类似

z = find(isnan(x_rec))';
        x_rec(z) = 0;

去掉用于图表的向量元素中的所有 nan。但当我运行 matlab2tikz 时,它仍然会生成这些 nan 值。MATLAB/LaTeX 内部是否有任何修复程序可用于解决此问题?任何意见都将不胜感激。

编辑1:已清除

编辑2:根据用户评论添加了请求的更改

编辑3:我完全按照您在回答中提出的建议去做了。

我做了一个稍微复杂一点的例子,但没有所有的轨迹,看看是否可以将它应用于更大的情况。

我收到以下错误输出:

/Users/.../Dropbox/Flight Models/F16 MRAC/Improvments/simulations/export/lqr_case3_test.tex:820:缺少数字,视为零。[\end{axis}] /Users/.../Dropbox/Flight Models/F16 MRAC/Improvments/simulations/export/lqr_case3_test.tex:820:缺少数字,视为零。[\end{axis}] /Users/.../Dropbox/Flight Models/F16 MRAC/Improvments/simulations/export/lqr_case3_test.tex:820:计量单位非法(插入 pt)。[\end{axis}]

代码附后:

\documentclass[tikz]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{grffile}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{patchplots}
\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}

\begin{axis}[%
width=6.028in,
height=1.258in,
at={(1.011in,4.137in)},
scale only axis,
unbounded coords=jump,
xmin=0,
xmax=30,
xlabel style={font=\color{white!15!black}},
xlabel={$t$ [s]},
ymin=-10,
ymax=10,
y filter/.expression={y < -10 ? -10 : y},
ytick = {-60,-40,-20,0,20,40,60},
xtick= {0,5,10,15,20,25,30},
ylabel style={font=\color{white!15!black}},
ylabel={$\mathrm{e}_\mathrm{y}(t)$},
axis background/.style={fill=white}
]
\addplot [color=red, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   0.0250000000000004\\
0.225   1.36640410626052\\
0.550000000000001   3.66846360239067\\
0.734999999999999   5.43159426472381\\
0.835000000000001   7.0507378365897\\
0.895   9.38393270887029\\
0.91    10.0927552846908\\
nan nan\\
3.66500026922157    12\\
3.66500031753162    -12.0000000004657\\
nan nan\\
3.67    -12\\
3.67    0\\
3.675   0\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   0.0249999999999986\\
0.280000000000001   1.6370323697279\\
0.895   5.13558618342118\\
1.055   5.65624972185001\\
1.165   5.81184548038762\\
1.255   5.80916803706801\\
1.35    5.68706639256226\\
1.475   5.36459283055524\\
1.65    4.67539967994115\\
1.925   3.25874343128647\\
2.685   -0.778615136549419\\
2.995   -2.00728838977296\\
3.27    -2.82961840280813\\
3.52    -3.36912972071364\\
3.75    -3.70645170333896\\
3.965   -3.89907957866767\\
4.17    -3.98573601618607\\
4.38    -3.98973916927921\\
4.61    -3.91197825503591\\
4.89    -3.72786561990029\\
5.29    -3.36109351637426\\
5.98    -2.72142546335244\\
6.305   -2.52330904689175\\
6.6 -2.42930040476483\\
6.9 -2.41511230157889\\
7.24    -2.47850829157946\\
7.74    -2.65831034340636\\
8.555   -2.95062946226752\\
9.045   -3.04361473371888\\
9.55    -3.06301039713165\\
10.2    -3.0085111146319\\
11.67   -2.86164686497091\\
12.555  -2.86647869875044\\
15.115  -2.92599469572881\\
19.18   -2.91197483014022\\
30  -2.9106034182126\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   0.0249999999999986\\
0.800000000000001   3.92833674935676\\
0.934999999999999   4.17981320935056\\
1.035   4.22642184061363\\
1.135   4.15819510968285\\
1.255   3.94161552152364\\
1.415   3.4693075759248\\
1.655   2.50146733277401\\
2.65    -1.78354534762907\\
2.945   -2.64527914096525\\
3.21    -3.21248214657945\\
3.45    -3.56773189037279\\
3.675   -3.77699356534631\\
3.89    -3.87777031338807\\
4.11    -3.89400879117792\\
4.35    -3.8281992229967\\
4.635   -3.66308262369212\\
5.045   -3.32585063525266\\
5.74    -2.74874675229397\\
6.08    -2.56605417864463\\
6.39    -2.48340500880336\\
6.71    -2.47810686998423\\
7.09    -2.55266028609768\\
7.76    -2.77927715685102\\
8.405   -2.96640163013104\\
8.915   -3.03829430189612\\
9.47    -3.04007843664711\\
10.305  -2.95856881470272\\
11.38   -2.86891905859731\\
12.305  -2.87105615896337\\
14.995  -2.92296994113278\\
18.825  -2.91151583479537\\
30  -2.91060084699089\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   0.0249999999999986\\
0.614999999999998   2.9594676385189\\
0.774999999999999   3.37173207277106\\
0.895   3.50567496620542\\
0.995000000000001   3.49965540453969\\
1.105   3.37882958531489\\
1.245   3.07786175100982\\
1.44    2.45453816524555\\
1.77    1.11346953767592\\
2.365   -1.29168860639218\\
2.685   -2.29680939514484\\
2.965   -2.96042656937263\\
3.22    -3.39228777889137\\
3.455   -3.65541529901873\\
3.68    -3.79849300849118\\
3.9 -3.84815421596938\\
4.135   -3.81767506252073\\
4.405   -3.69786847220901\\
4.755   -3.45076197073237\\
5.76    -2.68233605492718\\
6.09    -2.54821385412394\\
6.41    -2.499891994584\\
6.755   -2.52632877613248\\
7.21    -2.64330786852156\\
8.375   -2.97921595222244\\
8.9 -3.03619149848657\\
9.495   -3.02404227059002\\
12.07   -2.87013748185346\\
15.285  -2.91723047200099\\
18.42   -2.91054390317675\\
28.03   -2.91052760372732\\
30  -2.91059874204956\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   0.0249999999999986\\
0.484999999999999   2.29027571214776\\
0.664999999999999   2.82152621987229\\
0.795000000000002   3.0174316645557\\
0.899999999999999   3.05196004267977\\
1.005   2.98136286381544\\
1.135   2.76607486258512\\
1.305   2.31601874181512\\
1.57    1.37499236147566\\
2.43    -1.82943494695936\\
2.735   -2.64294980418621\\
3.005   -3.17391469541944\\
3.25    -3.50808804837014\\
3.48    -3.70466381814788\\
3.705   -3.79923392252075\\
3.935   -3.80958197442673\\
4.185   -3.73919343210429\\
4.49    -3.56724542481468\\
4.97    -3.19498024021948\\
5.54    -2.77287536388275\\
5.89    -2.60281003981768\\
6.215   -2.52699156693335\\
6.555   -2.527237975066\\
6.965   -2.60741550208735\\
8.59    -3.01541674797908\\
9.15    -3.03235157619397\\
9.915   -2.97450394373388\\
11.235  -2.87166123436934\\
12.24   -2.8788575988281\\
14.66   -2.9231400724234\\
19.565  -2.91228714677997\\
30  -2.91059708449782\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   0\\
0.225000000000001   0.00929884466341946\\
0.375   -0.0960353473451789\\
0.559999999999999   -0.335322397605349\\
0.824999999999999   -0.817435318026451\\
1.795   -2.70664746362509\\
2.1 -3.09952087337011\\
2.375   -3.33983872859375\\
2.635   -3.47200767452113\\
2.9 -3.52155753335949\\
3.185   -3.49449229438688\\
3.525   -3.38093160320136\\
4.07    -3.10468912833014\\
4.685   -2.81371276077929\\
5.095   -2.70032770347464\\
5.5 -2.66604186351515\\
5.97    -2.70501702787225\\
6.915   -2.88267072956114\\
7.63    -2.97390868270669\\
8.325   -2.98719541172152\\
9.49    -2.9206942839221\\
10.685  -2.88272804094323\\
12.78   -2.91782207888665\\
15.51   -2.90771019577319\\
30  -2.91057876269324\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   0\\
0.195   -0.0106641138940127\\
0.350000000000001   -0.125456706756925\\
0.539999999999999   -0.378647348087661\\
0.815000000000001   -0.886476330707641\\
1.715   -2.64547718202823\\
2.025   -3.05990051345608\\
2.305   -3.31682175796632\\
2.57    -3.46084752946946\\
2.835   -3.51800065380956\\
3.12    -3.49777770862539\\
3.455   -3.39223464567351\\
3.96    -3.14194159567752\\
4.635   -2.81817024214336\\
5.05    -2.70225054963423\\
5.455   -2.66703794911977\\
5.925   -2.70500264776918\\
6.84    -2.87638506335148\\
7.57    -2.97214955057043\\
8.26    -2.98752760652243\\
9.37    -2.92565747830996\\
10.6    -2.88290521979962\\
12.43   -2.91402213232269\\
14.615  -2.91196779956908\\
19.5    -2.91101526644729\\
30  -2.91057823795627\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   0\\
0.170000000000002   -0.0259092006762032\\
0.324999999999999   -0.148291728270944\\
0.52    -0.416013890082006\\
0.809999999999999   -0.960683213660769\\
1.635   -2.58112934463979\\
1.95    -3.01826956719705\\
2.23    -3.28901935504687\\
2.495   -3.44545130773956\\
2.76    -3.51364306335384\\
3.04    -3.50405104772951\\
3.365   -3.41181974748305\\
3.825   -3.19285618292798\\
4.615   -2.81150348004526\\
5.025   -2.7003230392131\\
5.43    -2.66765604913455\\
5.9 -2.70748771505458\\
6.92    -2.89707969449125\\
7.62    -2.97795200451552\\
8.33    -2.98424877138445\\
11.675  -2.89963521584007\\
13.91   -2.9170845906708\\
19.485  -2.91099215901118\\
30  -2.91057773521634\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   0\\
0.149999999999999   -0.0376167763427162\\
0.309999999999999   -0.176275191592094\\
0.515000000000001   -0.473095204099714\\
0.830000000000002   -1.08243995468164\\
1.545   -2.49666253621363\\
1.87    -2.96824507411351\\
2.155   -3.25958658110435\\
2.42    -3.42898693561992\\
2.685   -3.5087019240846\\
2.96    -3.50982980100805\\
3.275   -3.4308881556674\\
3.7 -3.23828946706975\\
4.625   -2.79447421706261\\
5.035   -2.69264279494998\\
5.445   -2.66868381968603\\
5.935   -2.71898168170251\\
7.76    -2.98606609595991\\
8.52    -2.9743232680257\\
10.87   -2.88468348900466\\
15.6    -2.90740184230529\\
30  -2.91057725244696\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   0\\
0.135000000000002   -0.0472173728549414\\
0.300000000000001   -0.20571953825009\\
0.515000000000001   -0.53544286672215\\
0.864999999999998   -1.23293864856134\\
1.47    -2.43299113980749\\
1.8 -2.92785505702136\\
2.09    -3.23693170399417\\
2.36    -3.41878336334402\\
2.625   -3.50571488583853\\
2.9 -3.51301577881385\\
3.21    -3.44095738179712\\
3.62    -3.26040830437778\\
4.625   -2.78167827959826\\
5.03    -2.6877320868041\\
5.44    -2.66949364938386\\
5.94    -2.72585877741539\\
7.635   -2.98276315284418\\
8.365   -2.97998204207448\\
11.145  -2.88961942978668\\
14.145  -2.91470617751462\\
18.88   -2.91145836286662\\
30  -2.91057678789504\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.0249999999999986\\
0.274999999999999   -1.20206488874739\\
0.585000000000001   -2.26427095573928\\
0.859999999999999   -2.97102531719836\\
1.11    -3.42923422559991\\
1.34    -3.70909545107574\\
1.56    -3.86341426798619\\
1.775   -3.9204822926082\\
2   -3.89570055725837\\
2.255   -3.78313707446429\\
2.575   -3.55115522094753\\
3.755   -2.59890266815656\\
4.065   -2.48732305198024\\
4.375   -2.45746489337836\\
4.72    -2.50396183359035\\
5.2 -2.6532947048627\\
6.145   -2.96056712198076\\
6.65    -3.03910648369724\\
7.19    -3.04659438243518\\
7.955   -2.9746906581829\\
9.13    -2.86853457467693\\
10.035  -2.86850436138026\\
12.85   -2.92231622014178\\
16.36   -2.91074585034381\\
25.495  -2.91049996698134\\
30  -2.91056484919045\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.0249999999999986\\
0.300000000000001   -1.33824031805886\\
0.600000000000001   -2.3714134030318\\
0.870000000000001   -3.06161115683177\\
1.115   -3.50339622059839\\
1.34    -3.76927994759397\\
1.555   -3.91235121715328\\
1.765   -3.96068711221261\\
1.985   -3.92888255936124\\
2.24    -3.80675679030313\\
2.56    -3.56130865486864\\
3.705   -2.59137710763003\\
4.01    -2.47081971809983\\
4.31    -2.43379068468667\\
4.64    -2.47242400097117\\
5.08    -2.60762041174088\\
6.165   -2.97492388017931\\
6.66    -3.04842596327237\\
7.195   -3.05098314200486\\
7.97    -2.97175609806559\\
9.08    -2.86725985563066\\
9.955   -2.86502154839857\\
12.92   -2.92144645575311\\
16.11   -2.90981339140987\\
23.745  -2.91063366149451\\
30  -2.91056425321359\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.0249999999999986\\
0.329999999999998   -1.49647236589962\\
0.620000000000001   -2.49200390389539\\
0.879999999999999   -3.14979248977517\\
1.12    -3.5751352790566\\
1.34    -3.82748958587267\\
1.55    -3.9599613659672\\
1.76    -4.00028445229783\\
1.98    -3.95869400947779\\
2.235   -3.82422731042085\\
2.56    -3.55844845993077\\
3.635   -2.59750847949297\\
3.935   -2.46130666234685\\
4.225   -2.41095501483639\\
4.54    -2.43602650171722\\
4.935   -2.54965340071062\\
6.285   -3.00932757634062\\
6.77    -3.06257384983658\\
7.32    -3.04624883380401\\
8.38    -2.9196175731384\\
9.23    -2.8588410437232\\
10.15   -2.87103657198714\\
12.375  -2.92810760851598\\
18.895  -2.91050482985815\\
30  -2.91056366450105\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.0249999999999986\\
0.359999999999999   -1.65641891377859\\
0.640000000000001   -2.61098043336424\\
0.895   -3.24610881740123\\
1.13    -3.65156823751095\\
1.35    -3.89211953760948\\
1.555   -4.00992174705381\\
1.76    -4.03873138010252\\
1.98    -3.98587551556846\\
2.235   -3.83777769231098\\
2.57    -3.54527532783231\\
3.565   -2.60809976014544\\
3.865   -2.4532729031278\\
4.15    -2.38943759633281\\
4.45    -2.40188599130338\\
4.815   -2.49867839848785\\
5.545   -2.79586832898719\\
6.105   -2.98004949667065\\
6.58    -3.0590530004365\\
7.085   -3.06664117183348\\
7.775   -2.99599739835937\\
9.01    -2.86373217966083\\
9.84    -2.85896378349899\\
12.995  -2.92033647175875\\
15.825  -2.90852932223133\\
22.45   -2.9108461927486\\
30  -2.9105630821746\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.0249999999999986\\
0.390000000000001   -1.81722743324358\\
0.66    -2.72819443416642\\
0.91    -3.33982793855921\\
1.14    -3.72545241788654\\
1.355   -3.95031790542177\\
1.56    -4.0579082873189\\
1.765   -4.07538277794475\\
1.985   -4.00971088257987\\
2.245   -3.84270204314688\\
2.59    -3.520225126893\\
3.495   -2.62367560104087\\
3.8 -2.44645392469467\\
4.08    -2.36919304831473\\
4.37    -2.36980880650644\\
4.71    -2.45156152118109\\
5.245   -2.67163390173442\\
5.945   -2.94543566501993\\
6.415   -3.04934724062867\\
6.89    -3.07855132800174\\
7.47    -3.03649164972677\\
9.26    -2.85211939675092\\
10.175  -2.87099417389278\\
12.175  -2.930626562251\\
23.39   -2.91070611943666\\
30  -2.91056250542613\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.0500000000000007\\
0.239999999999998   -2.1013993818721\\
0.465   -3.4754778485589\\
0.675000000000001   -4.35408195140127\\
0.864999999999998   -4.87370006882766\\
1.04    -5.16156972907208\\
1.2 -5.28982791015084\\
1.35    -5.30919453211669\\
1.505   -5.23963076486467\\
1.685   -5.0592178178678\\
1.9 -4.72396148610697\\
2.17    -4.15432048360901\\
2.555   -3.1542087328128\\
3.14    -1.6423670592747\\
3.38    -1.2122001585339\\
3.575   -1.00215317891411\\
3.74    -0.929310678745253\\
3.905   -0.947235698648832\\
4.09    -1.05981374579387\\
4.325   -1.30842239640324\\
4.7 -1.83574690243072\\
5.305   -2.67760918290799\\
5.645   -3.02690702564796\\
5.95    -3.23801697777402\\
6.24    -3.34962347213457\\
6.54    -3.38301081641513\\
6.875   -3.34037876214411\\
7.305   -3.20345716593312\\
8.45    -2.79612924424488\\
8.905   -2.73357118511085\\
9.4 -2.74188442632862\\
10.155  -2.83955734400922\\
11.15   -2.9543736209882\\
11.94   -2.96785733012477\\
15.905  -2.91127088480729\\
18.455  -2.91053997524352\\
25.76   -2.91046778232075\\
30  -2.91053994662252\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.0500000000000007\\
0.25    -2.20769666004746\\
0.469999999999999   -3.55664609306002\\
0.675000000000001   -4.42018781002623\\
0.864999999999998   -4.94283600936899\\
1.04    -5.22957861461928\\
1.195   -5.35218539940045\\
1.345   -5.36953809017305\\
1.5 -5.29591812490685\\
1.68    -5.108499793968\\
1.895   -4.76176299148891\\
2.165   -4.17275730859139\\
2.545   -3.14898673148741\\
3.155   -1.50254570212858\\
3.39    -1.06785281405378\\
3.575   -0.862074468320337\\
3.74    -0.78736268742659\\
3.9 -0.807523728348723\\
4.08    -0.923765778757737\\
4.31    -1.18091302140832\\
4.675   -1.72497909104881\\
5.295   -2.64589241067019\\
5.63    -3.01446189068668\\
5.93    -3.24000687184254\\
6.215   -3.36312884053187\\
6.505   -3.40594131253556\\
6.825   -3.37355219866218\\
7.225   -3.25083128313881\\
8.57    -2.76527321395537\\
9.015   -2.71933836593889\\
9.525   -2.74448713952928\\
10.525  -2.89104003932955\\
11.32   -2.9657965021405\\
12.13   -2.96536334497646\\
14.965  -2.89505804041291\\
18.08   -2.91268756183939\\
24.035  -2.91038130974669\\
30  -2.91053812274255\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.0500000000000007\\
0.260000000000002   -2.3146422701057\\
0.48    -3.6623297426928\\
0.684999999999999   -4.51866795546376\\
0.875   -5.03139213570601\\
1.045   -5.3016191556785\\
1.2 -5.41717082411357\\
1.345   -5.42761159790457\\
1.5 -5.34731869597687\\
1.68    -5.15029287651623\\
1.895   -4.78948451614948\\
2.165   -4.17853659769283\\
2.54    -3.12972531172379\\
3.17    -1.35335074608681\\
3.4 -0.912874277302503\\
3.585   -0.702756101780402\\
3.745   -0.632112680082194\\
3.9 -0.656418325370947\\
4.075   -0.778115090131607\\
4.295   -1.03868266670327\\
4.64    -1.58255051696043\\
5.29    -2.61434643362309\\
5.625   -3.00722042232988\\
5.92    -3.24536169173127\\
6.2 -3.37835411706832\\
6.485   -3.42919360813307\\
6.795   -3.40374297024233\\
7.17    -3.29161960140139\\
8.69    -2.73727581293189\\
9.13    -2.70809021262213\\
9.66    -2.75169625919522\\
11.515  -2.9751323773358\\
12.37   -2.95793429255127\\
14.45   -2.88779953828692\\
23.755  -2.91050894594513\\
30  -2.91053617600944\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.0500000000000007\\
0.274999999999999   -2.45831927793042\\
0.495000000000001   -3.79213518215216\\
0.699999999999999   -4.63189350931196\\
0.890000000000001   -5.12779864848405\\
1.06    -5.38239094205919\\
1.21    -5.48186796981356\\
1.355   -5.48145232270446\\
1.51    -5.38882363837184\\
1.69    -5.17648498226255\\
1.905   -4.79583274051691\\
2.175   -4.15713042960357\\
2.55    -3.0635921907106\\
3.19    -1.18147203703593\\
3.415   -0.737541147555692\\
3.595   -0.529234365978727\\
3.75    -0.461667952569854\\
3.9 -0.489243219941915\\
4.07    -0.615672112102875\\
4.285   -0.885947612797008\\
4.62    -1.44700162709157\\
5.29    -2.58270838142746\\
5.62    -2.99563919741663\\
5.91    -3.24809123425851\\
6.185   -3.39246013521914\\
6.46    -3.45236305615962\\
6.755   -3.43720055558367\\
7.105   -3.33917477251393\\
7.655   -3.09416862975146\\
8.305   -2.82263073649932\\
8.74    -2.72129207608271\\
9.175   -2.69747323413537\\
9.7 -2.74748733648617\\
11.44   -2.9761719377818\\
12.235  -2.96749698740096\\
14.68   -2.88863578369338\\
18.875  -2.90870990617637\\
28.675  -2.91058786952115\\
30  -2.91053408390272\\
};
\addplot [color=blue, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.0500000000000007\\
0.285   -2.56617176414469\\
0.5 -3.87099263960091\\
0.699999999999999   -4.69409745834623\\
0.885000000000002   -5.18214950871553\\
1.055   -5.44019797482534\\
1.205   -5.54006742670913\\
1.35    -5.53806884951605\\
1.505   -5.44187237620586\\
1.685   -5.22312876204089\\
1.9 -4.83165158541487\\
2.165   -4.18759591913246\\
2.525   -3.10648531533846\\
3.23    -0.947480503318733\\
3.445   -0.523095243355851\\
3.615   -0.330627263402274\\
3.765   -0.271601665455648\\
3.91    -0.307247852569638\\
4.075   -0.443056114063847\\
4.29    -0.735606671402966\\
4.625   -1.33844790915064\\
5.28    -2.5271919871305\\
5.61    -2.97268237607013\\
5.9 -3.24729223504812\\
6.17    -3.40491441951095\\
6.44    -3.4758188175106\\
6.725   -3.47021918690878\\
7.055   -3.38412438895698\\
7.525   -3.17449974062785\\
8.315   -2.81802625680392\\
8.74    -2.71225351954811\\
9.16    -2.6847665667893\\
9.66    -2.73030820959707\\
11.545  -2.98246204843722\\
12.355  -2.96512074484801\\
14.46   -2.88517980208828\\
23.735  -2.91052811847904\\
30  -2.91053181820566\\
};
\addplot [color=red, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.0749999999999993\\
0.23    -2.99335929030486\\
0.44    -4.83721959626826\\
0.625   -5.91359501614679\\
0.795   -6.53438569007465\\
0.945   -6.84520220791225\\
1.075   -6.96496001136622\\
1.195   -6.96869658768607\\
1.325   -6.86943727274824\\
1.475   -6.63306777251381\\
1.655   -6.18788236522535\\
1.86    -5.46738342204405\\
2.07    -4.46169733103213\\
2.26    -3.20869226322372\\
2.4 -1.82997044923824\\
2.485   -0.301252624619764\\
2.555   2.69755754709442\\
2.715   10.1605991842363\\
nan nan\\
5.475   12\\
5.475   0\\
5.48    0\\
};
\addplot [color=red, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.0749999999999993\\
0.234999999999999   -3.07504197109234\\
0.44    -4.88487217172767\\
0.625   -5.97061365214432\\
0.795   -6.59510793157538\\
0.945   -6.90625212921105\\
1.075   -7.02455678990381\\
1.195   -7.02573575342825\\
1.325   -6.92247779247674\\
1.475   -6.67985646034357\\
1.65    -6.23943786760617\\
1.85    -5.52844334001679\\
2.06    -4.50851435292791\\
2.25    -3.22291887693328\\
2.385   -1.83332912220445\\
2.465   -0.284528066707781\\
2.55    3.51406407236719\\
2.69    10.0383903749761\\
nan nan\\
5.44501271491125    12\\
5.44501506782844    -12\\
nan nan\\
5.45    -12\\
5.45    0\\
5.455   0\\
};
\addplot [color=red, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.125\\
0.25    -3.125\\
0.5 -5\\
0.625   -6\\
0.75    -6.625\\
1   -7\\
1.125   -7.125\\
1.25    -7.125\\
1.375   -7\\
1.5 -6.75\\
1.625   -6.25\\
1.875   -5.5\\
2   -4.5\\
2.25    -3.25\\
2.375   -1.875\\
2.5 -0.25\\
2.5 4.25\\
2.625   10.125\\
nan nan\\
5.375   12\\
5.375   -12\\
nan nan\\
5.375   -12\\
5.375   562949953421312\\
5.375   0\\
};
\addplot [color=red, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.0749999999999993\\
0.244999999999999   -3.23812572616739\\
0.449999999999999   -5.04842286572111\\
0.635   -6.12605915883983\\
0.805   -6.73845996143639\\
0.955   -7.03644450286898\\
1.085   -7.1418125959604\\
1.2 -7.13224363845064\\
1.325   -7.02358150521751\\
1.475   -6.7689305649121\\
1.65    -6.30929845711167\\
1.85    -5.56605890414069\\
2.055   -4.5180911088989\\
2.235   -3.21724073543972\\
2.36    -1.7953461538192\\
2.43    -0.19196484983669\\
2.605   7.93761069821436\\
2.65    10.031625790651\\
nan nan\\
5.40502073640448    12\\
5.4050245831541 -12\\
nan nan\\
5.41    -11.9999999999964\\
5.41    0\\
5.415   0\\
};
\addplot [color=red, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.0749999999999993\\
0.25    -3.31944929564987\\
0.455   -5.12859099588588\\
0.640000000000001   -6.20136790765752\\
0.81    -6.80729412900045\\
0.955   -7.09201415044333\\
1.08    -7.19431047868527\\
1.195   -7.18641462002113\\
1.32    -7.07815031620275\\
1.47    -6.82214840684085\\
1.645   -6.35827029226641\\
1.845   -5.6054949269188\\
2.045   -4.56848194595005\\
2.22    -3.28570818438998\\
2.34    -1.9072063974549\\
2.41    -0.295846883105275\\
2.59    8.07013601787988\\
2.635   10.1640590537284\\
nan nan\\
5.395   12\\
5.395   0\\
5.4 0\\
};
\end{axis}
\end{tikzpicture}
\end{document}

答案1

我无法在我的计算机上重现您的错误,但关于您需要的输出,您可以在环境y filter中添加选项axis。这会将一些代码应用于数据集的任何 y 值。请参阅 pgfplots 手册第 4.22 节 p386。

在您的情况下,表达式y filter/.expression={y < -60 ? -60 : y}检查数据点的 y 值是否低于 -60,如果是,则将值更改为 -60,如果不是,则保留其初始值。

一般来说,在图形渲染软件中,nan用于使东西不可见,同时保持良好的对象尺寸,在您的情况下,是两个列矩阵。

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{grffile}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{patchplots}
\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}

\begin{axis}[%
width=6.028in,
height=4.754in,
at={(1.011in,0.642in)},
scale only axis,
%unbounded coords=jump,
xmin=0,
xmax=30,
ymin=-60,
ymax=60,
y filter/.expression={y < -60 ? -60 : y},
ytick = {-60,-40,-20,0,20,40,60},
xtick= {0,5,10,15,20,25,30},
axis background/.style={fill=white}
]
\addplot [color=red, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
0   0\\
nan nan\\
0   0\\
0   -0\\
nan nan\\
0   -0\\
0   0\\
0   -5.90295810358706e+20\\
0   0\\
};
\end{axis}
\end{tikzpicture}%
\end{document}

在此处输入图片描述 与 OP EDIT3 相关的更新

我通过删除与您指出的错误无关的所有部分来简化您的 MWE,并修改了过滤标准,以便y filter/.expression={abs(y) > 10 ? sign(y)*10 : y}将任何过大的值(绝对值大于 10)设置为 +-10,从而解决了由于这个 y 值导致的错误562949953421312

总结一下我的回答,价值没有问题nan,而是数值大,这是完全正常的。

\documentclass[tikz]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{grffile}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{patchplots}
\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}

\begin{axis}[%
width=6.028in,
height=1.258in,
at={(1.011in,4.137in)},
scale only axis,
unbounded coords=jump,
xmin=0,
xmax=30,
xlabel style={font=\color{white!15!black}},
xlabel={$t$ [s]},
ymin=-10,
ymax=10,
y filter/.expression={abs(y) > 10 ? sign(y)*10 : y},
ytick = {-60,-40,-20,0,20,40,60},
xtick= {0,5,10,15,20,25,30},
ylabel style={font=\color{white!15!black}},
ylabel={$\mathrm{e}_\mathrm{y}(t)$},
axis background/.style={fill=white}
]
\addplot [color=red, line width=2.0pt, forget plot]
  table[row sep=crcr]{%
0   -0.125\\
0.25    -3.125\\
0.5 -5\\
0.625   -6\\
0.75    -6.625\\
1   -7\\
1.125   -7.125\\
1.25    -7.125\\
1.375   -7\\
1.5 -6.75\\
1.625   -6.25\\
1.875   -5.5\\
2   -4.5\\
2.25    -3.25\\
2.375   -1.875\\
2.5 -0.25\\
2.5 4.25\\
2.625   10.125\\
nan nan\\
5.375   12\\
5.375   -12\\
nan nan\\
5.375   -12\\
5.375   562949953421312\\
5.375   0\\
};

\end{axis}
\end{tikzpicture}
\end{document}

相关内容