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


\title{  Experimental Results & Plots }
\author{John doe }
\date{February 2019}

    \csname pgfplots@init@cleared@structures\endcsname
    % draws the legend:
    \csname pgfplots@createlegend\endcsname

\def\addlegendimage{\csname pgfplots@addlegendimage\endcsname}
    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},
    \title{  Gaussian Compressionh}
        \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}

    }\hfill ~

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


\caption{plot of nmf }\label{fig:RRE1}

enter image description here

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


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.


        ticklabel style = {font=\Large},
        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};



enter image description here

|improve this answer|||||
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.