0

I extracted data from matlab figures, with the command "dlmwrite('heat.txt',[x',u],'delimiter', '\t')". It gives me a text file with 3 columns of numbers (the first is the abscisse x, and the other are 2 functions f(x) and g(x)). I wanted to plot it in Latex, so i've written this:

\begin{tikzpicture}
\begin{axis}
\addplot {heat.txt};
\end{axis}
\end{tikzpicture}

It's not working, I have the error : ! Package PGF Math Error: Unknown function `heat' (in 'heat.txt').. Then, I put file[skip first] in the line \addplot and it's working, I have the graph of (x,f(x)). I don't understand because my text file is only number. More important, I wanted to plot also (x,g(x)). So i've written:

\begin{tikzpicture}
\begin{axis}
\addplot file[skip first] table[x index=0,y index=2] {heat.txt};
\end{axis}
\end{tikzpicture}

And it does not work, the error is : ! Package pgfplots Error: sorry, plot file{t} could not be opened. I tried it without "file[skip first]", and it's the same error.

I really don't understand.

0

To plot coordinates from a file use

\addplot table [<column selection>]{<file name>};

If the optional argument for table is missing, the first column (with index 0) is used as x values and the second column (with index 1) is used as y-values.

To plot f(x) with your file

\begin{tikzpicture}
\begin{axis}
\addplot table {heat.txt};
\end{axis}
\end{tikzpicture}

should work.

To plot the third column you can use:

\begin{tikzpicture}
\begin{axis}
\addplot table[x index=0,y index=2] {heat.txt};
\end{axis}
\end{tikzpicture}

From the manual:

If you have data files, you should generally use \addplot table. The input type \addplot file is almost the same, but considerably less powerful. It is only kept for backwards compatibility.

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.