
Ich versuche, Daten aus einer CSV-Datei darzustellen. Ich habe viele CSV-Dateien (etwa 4000). Ich bin nicht sicher, wie ich das machen soll. Ich suche nach einer Art „for-Schleife“, um das durchzuführen. Für jede Hilfe wäre ich dankbar. Ich habe unten einen Beispielcode angehängt.
Ich habe viele Datendateien und möchte nicht für alle CSV-Dateien eine Codezeile hinzufügen. Ich hoffe, das erklärt mein Problem.
%\title{Plot_for_gain_tuning_paper}
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{4pt}
\pgfplotsset{width=9.75cm,compat=1.3}
\pgfplotsset{every axis legend/.append style={at={(0.45,-0.25)},legend columns=5,anchor=south,font=\small}}
\tikzset{every mark/.append style={scale=0.8}}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[title=$V_{a_{rms}}+V_{b_{rms}}+V_{c_{rms}}$,xlabel={Time (in seconds)},ylabel={Voltage (in Volts)},grid=major,legend entries={$Index~1$,$Index~2$,$Index~3$,$Index~4$,$Index~5$}]
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_1.csv};
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_2.csv};
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_3.csv};
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_4.csv};
\end{axis}
\end{tikzpicture}
\end{document}
Antwort1
Für eine Sammlung von Dateien mit einer regelmäßigen „Fortschrittsfolge“ von Dateinamen kann der \foreach
Befehl (aus dem Paket pgffor
, einem Utility-Paket für tikz
) hilfreich sein. Anstatt
\begin{tikzpicture}
\begin{axis}[title=$V_{a_{rms}}+V_{b_{rms}}+V_{c_{rms}}$,xlabel={Time (in seconds)},ylabel={Voltage (in Volts)},grid=major,legend entries={$Index~1$,$Index~2$,$Index~3$,$Index~4$,$Index~5$}]
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_1.csv};
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_2.csv};
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_3.csv};
...
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_1000.csv};
\end{axis}
\end{tikzpicture}
du könntest haben:
\begin{tikzpicture}
\begin{axis}[
title=$V_{a_{rms}}+V_{b_{rms}}+V_{c_{rms}}$,
xlabel={Time (in seconds)},
ylabel={Voltage (in Volts)},
grid=major,
legend entries={$Index~1$,$Index~2$,$Index~3$,$Index~4$,$Index~5$}
]
\foreach \F in {1,2,...,1000}{
\addplot[
color=black,
style=solid,
very thick
] table [col sep=comma] {Data_128_4_\F.csv};
}
\end{axis}
\end{tikzpicture}