0

I want to make variable "list" containing filenames, variable "i" containing number of datafiles and plot it into single graph. Example of filenames: ConvAut.dat, ConvMoveAut.dat, CutAut.dat ... Here is my try:

list = system("echo $(dir *.dat)")
plot for [1:i] i using 1:((2*i)+(column(2))) w steps tit i

I just found this piece of code but i dont know how to edit it. I have version 4.6 patchlevel 0. Can you help me? Thanks for the answers

1 Answer 1

1
list = system("dir /b *.dat") # Windows
# list = system("ls *.dat") # Unix
plot for [i=1:words(list)] word(list, i) using 1:((2*i)+column(2)) w steps title word(list, i)

The list is a string which contains all files, separated by white spaces. In the plot command you could also iterate over this file list with plot for [file in list] file ..., but then you don't have access to the file number. So I used words to get the number of files, and word(list, i) to get the i-th file name.

Note, that this works only if the file names don't contain white spaces.

Sign up to request clarification or add additional context in comments.

2 Comments

In Unix, one way to handle file names containing white spaces is list = system("ls *.txt | xargs -I line echo \\\"line\\\" ")
@vagoberto Thanks for the addition. That would work with gnuplot 5, which has limited support for handling quoted strings with word.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.