如何在 GNUplot 中定义和访问数组? [英] How to define and access array in GNUplot?

查看:45
本文介绍了如何在 GNUplot 中定义和访问数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个相当简单的问题,或者可能是太简单的问题.但是我已经尝试找到完成这些的方法,甚至在 GNUplot 文档中也找不到.可能是我的错误或误解了 GNUplot 中的 array 概念.我的问题是如何在 GNUplot 中定义和访问数组?

This is rather easy question or maybe too easy question. But i tried to find the way to done these already and could not find even in GNUplot document. Might be my mistake or misunderstood something about array concept in GNUplot. My question is How to define and access array in GNUplot?

请提供简单的数组声明示例,循环赋值数组.我认为这就足够了,我认为这对其他人也有用.

Please just provide easy example of array declaration, assign value of array over loop. i think that's enough and i think this will be useful for other people too.

推荐答案

(此答案将在下一个稳定的 gnuplot 版本中过时,因为 5.1 开发树现在具有对数组变量的本机支持.)

(This answer will be obsolete with the next stable gnuplot release, as the 5.1 development tree now has native support for array variables.)

gnuplot 中的splot"命令使用关键字array"来定义包含 3D 绘图函数值的 NxM 矩阵的大小.

The "splot" command in gnuplot uses the keyword "array" to define the size of NxM matrix that contains function values for a 3D plot.

像程序员从 C、Pascal、Python 等中了解到的那样的数组在今天的 gnuplot (gp5.0) 中不存在.它们可能有一天会实施,因为它们对于绘制具有任意(例如拟合)参数的曲线族非常有用.

Arrays like what a programmer knows from C, Pascal, Python, etc. do not exist in gnuplot today (gp5.0). They might get implemented one day, because they'd be highly useful to plot a family of curves with arbitrary (e.g. fitted) parameters.

如果您对 gnuplot 中的数组感到绝望,您可以 (ab) 使用 word() 函数(和其他字符串函数)来实现有限的替代.也有点麻烦:

If you are desperate about arrays in gnuplot, you can (ab)use the word() function (and other string functions) to achieve a somewhat limited substitute. It's also a bit cumbersome:

array = ""
f(a,x) = a*x
do for [i=1:5] {array = array.sprintf(" %.3f",i+rand(0)) }
print "array = ".array
set xr [0:]; set yr [0:30]
plot for [i=1:5] f(word(array,i),x) title word(array,i)." x"

此示例将一组随机数写入名为array"的字符串变量,然后使用它绘制五个线性函数,这些函数使用array"中的数字作为斜率.

This example writes a set of random numbers to a string variable named "array", and afterwards uses it to plot five linear functions that use the numbers in "array" for their slope.

这篇关于如何在 GNUplot 中定义和访问数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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