É necessário adicionar um loop for para adicionar muitos arquivos .csv no tikzpicture

É necessário adicionar um loop for para adicionar muitos arquivos .csv no tikzpicture

insira a descrição da imagem aqui

Estou tentando plotar dados de um arquivo .csv. Tenho muitos arquivos .csv (cerca de 4.000). Não sei ao certo como fazer isso. Estou procurando algum tipo de "loop for" para realizar isso. Qualquer ajuda seria apreciada. Anexei um código de exemplo abaixo.

Tenho muitos arquivos de dados e não quero adicionar uma linha de código para todos os arquivos .csv. Espero que isso explique meu problema.

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

Responder1

Para uma coleção de arquivos que possui uma 'progressão' regular de nomes de arquivos, o \foreachcomando (do pacote pgffor, um pacote de utilitários para tikz) pode ser útil. Em vez de

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

você pode ter:

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

informação relacionada