Latex 无法读取我的 .dat 文件

Latex 无法读取我的 .dat 文件

我从 Matlab 编写了一个 .dat 文件。该数据有 8 列,每列有 1x101 个值。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots,tikz,graphicx}

\title{  Experimental Results & Plots }
\author{John doe }
\date{February 2019}
\usepackage{natbib}
\usepackage{graphicx} 
\newenvironment{customlegend}[1][]{%
    \begingroup

    \csname pgfplots@init@cleared@structures\endcsname
    \pgfplotsset{#1}%
}{%
    % draws the legend:
    \csname pgfplots@createlegend\endcsname
    \endgroup
}%

\def\addlegendimage{\csname pgfplots@addlegendimage\endcsname}
\pgfplotsset{
    cycle list={%
        {draw=black,solid,line width=2pt},
        {draw=black, dashed,line width=2pt},%densely dashed}, 
        {draw=red,solid,line width=2pt},%dashdotted}, %every mark/.append style={rotate=90},
        {draw=red, dashed,line width=2pt},
}}
\definecolor{darkgreen}{rgb}{0.125,0.5,0.169}
\usepackage{caption}
\begin{document}
    \title{  Gaussian Compressionh}
    \maketitle
 \begin{figure*}[ht]
    %\hspace{10ex}
    ~\hfill
    \resizebox{.6\textwidth}{!}{
        \begin{tikzpicture}
        \begin{customlegend}[legend columns=4,legend style={align=left,draw=none,column sep=2ex},legend entries={{AS-V},{AS-GC},{AS-GC-RE},{AS-RSI}}]
        \addlegendimage{brown, solid,line width=2pt}
        \addlegendimage{brown, dashed,line width=2pt}
        \addlegendimage{black, solid,line width=2pt}
        \addlegendimage{black, dashed,line width=2pt}

        \end{customlegend}
        \end{tikzpicture}
    }\hfill ~
    \pgfplotsset{compat=1.11}

    \resizebox{0.5\textwidth}{!}{\begin{tikzpicture}
        \begin{semilogyaxis}[ ticklabel style = {font=\Large} , ytick={1,1.e-2,1.e-4,1.e-6,1.e-8} , ymax=1, ymin=1.e-9 , xmin=1 , xmax=101, xlabel=\Large{iterations} , ylabel=\Large{Relative Recons. Error} , legend style={at={(0.03,0.97)},anchor=north west}]
        \addlegendimage{empty legend}\addlegendentry{\Large{ $\nu =1$}}

        \addplot[green,line width=2pt] table[x=[1:101], y=aS_V]{nu_150_pass.dat};
        \addplot[brown,line width=2pt, dashed] table[x=[1:101], y=aS_GC]{nu_150_pass.dat};
        \addplot[black,line width=2pt] table[x=[1:101], y=aS_RSI]{nu_150_pass.dat};
        \addplot[black,line width=2pt, dashed] table[x=[1:101], y=aS_GC_RE]{nu_150_pass.dat};

        \end{semilogyaxis}

 \end{tikzpicture}
}
\caption{plot of nmf }\label{fig:RRE1}
\end{figure*}
\end{document}

在此处输入图片描述

因此,y 轴将使用 dat 文件中的标题句柄来选择值。由于每列有 101 个值,因此我的 x 轴应该从 1:101 开始。但 latex 无法读取表格。我不知道为什么创建 .dat 文件的 Matlab 代码

    T=table(aS_V',aS_GC',aS_RSI',aS_GC_RE',neNMF_GC',neNMF_RSI',neNMF_GC_RE',...
neNMF_V','VariableNames','aS_V','aS_GC','aS_RSI','aS_GC_RE','neNMF_GC',...
'neNMF_RSI','neNMF_GC_RE','neNMF_V'});

namedatfile= ['nu_' int2str(nu) '_pass.dat'];
fname = namedatfile;
writetable(T,fname,'Delimiter',' ')  

链接:获取我的 nu_150.dat 文件 https://www.sendspace.com/file/ytu593

答案1

x 坐标可以用语法指定x expr=\coordindex,这意味着表格的行索引用作 x 值。您也可以指定col sep=space以确保pgfplots理解数据文件中的列分隔符。

梅威瑟:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
        \begin{semilogyaxis}[
        ticklabel style = {font=\Large},
        ytick={1,1.e-2,1.e-4,1.e-6,1.e-8},
        ymax=1,
        ymin=1.e-9,
        xmin=1,
        xmax=101,
        xlabel=\Large{iterations},
        ylabel=\Large{Relative Recons. Error}
        ]
        \addplot[green,line width=2pt] table[x expr=\coordindex, y=aS_V, col sep=space]{nu_150_pass.dat};
        \addplot[brown,line width=2pt, dashed] table[x expr=\coordindex,y=aS_GC, col sep=space]{nu_150_pass.dat};
        \addplot[black,line width=2pt] table[x expr=\coordindex,y=aS_RSI, col sep=space]{nu_150_pass.dat};
        \addplot[black,line width=2pt, dashed] table[x expr=\coordindex,y=aS_GC_RE, col sep=space]{nu_150_pass.dat};
        \legend{AS-V,AS-GC,AS-GC-RE,AS-RSI}
        \end{semilogyaxis}

\end{tikzpicture}
\end{document}

结果:

在此处输入图片描述

相关内容