如何将gnuplot输出文件定义为变量?

ale*_*lex 4 bash gnuplot

在我的bash文件中,我有这个声明:

gnuplot -e "filename='Traffic1'" MyplotFile
Run Code Online (Sandbox Code Playgroud)

现在我想通过Traffic1或更好的方式将filename的值称为我的gnuplot输出文件的名称,该文件是png格式.

我在MyplotFile上有这些行:

set output 'filename.png'
Run Code Online (Sandbox Code Playgroud)

但输出是filename.png!我希望将Traffic1.png作为输出.如何正确定义此行:

set output 'filename.png'
Run Code Online (Sandbox Code Playgroud)

PS如果您需要了解-e,请转到此链接

Chr*_*oph 8

随着'filename.png'你简单地定义一个字符串.gnuplot应该怎么知道,你的意思是变量?

您可以将变量与扩展字符串连接起来

set output filename . '.png'
Run Code Online (Sandbox Code Playgroud)

或者您可以使用sprintf:

set output sprintf('%s.png', filename)
Run Code Online (Sandbox Code Playgroud)