# Latex cant read from my .dat file

I wrote a .dat file from Matlab. this data has 8 columns each having 1x101 values.

\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
}%

\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}}]

\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$}}

\end{semilogyaxis}

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


So the y axis will pick values using the header handles from the dat file. and since each column has 101 values my x axis should go from 1 :101. But latex cant read the table. i dont know why Matlab code that created the .dat file

    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',' ')


Link: to get my nu_150.dat file https://www.sendspace.com/file/ytu593

• Error from latex: "Package pgfplots Error: Sorry, could not retrieve column 'aS_V' from table '\name aliases).. }" – Farouk Yahaya Feb 18 at 10:35
• Hi and welcome. Please give a fully compilable code. – AndréC Feb 18 at 10:57
• how do i edit the question please – Farouk Yahaya Feb 18 at 11:07
• At the very bottom left of your question is the text share edit close flag click on edit. – AndréC Feb 18 at 11:14
• Could you edit a small part of your data file (for example 2 columns and 5 rows) to your question in text format? Open the nu_150_pass.dat file in a text editor (so not in a spreadsheet program like in your screenshot) and copy-paste the text from there. It would be useful to see which delimiters are used in the file, for example. – Marijn Feb 18 at 11:39

The x coordinate can be specified with the syntax x expr=\coordindex, which means that the row index of the table is used as x value. Optionally you can specify col sep=space to make sure pgfplots understands the column separator in the data file.

MWE:

\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}


Result:

• wow, a million thanks. Its perfect. – Farouk Yahaya Feb 18 at 13:29
• @FaroukYahaya If this answer solved your problem, you can upvote it by pressing the up arrow on the left of the question and/or accept it by pressing the Checkmark. – Marcel Krüger Feb 22 at 0:39