如何传递命令行参数到gnuplot? [英] How to pass command line argument to gnuplot?

查看:421
本文介绍了如何传递命令行参数到gnuplot?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用gnuplot从数据文件中绘制数据,例如: foo.data 。目前,我在命令文件中硬编码数据文件名,例如 foo.plt ,并运行命令 gnuplot foo.plg 来绘制数据。但是,我想传递数据文件名作为命令参数,例如。运行命令 gnuplot foo.plg foo.data 。如何解析gnuplot脚本文件中的命令行参数?

I want to use gnuplot to draw figure from data file, say foo.data. Currently, I hardcoded the data file name in the command file, say foo.plt, and run command gnuplot foo.plg to plot data. However, I want to pass the data file name as a command argument, e.g. running command gnuplot foo.plg foo.data. How to parse the command line arguments in gnuplot script file? Thanks.

推荐答案

您可以通过开关输入变量 -e p>

You can input variables via switch -e

$ gnuplot -e "filename='foo.data'" foo.plg

在foo.plg中,您可以使用该变量

In foo.plg you can then use that variable

$ cat foo.plg 
plot filename
pause -1

foo.plg更通用,使用条件:

To make "foo.plg" a bit more generic, use a conditional:

if (!exists("filename")) filename='default.dat'
plot filename
pause -1

这篇关于如何传递命令行参数到gnuplot?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆