gnuplot-如何将函数打印到txt文件

发布于 2025-02-02 20:23:47 字数 247 浏览 3 评论 0原文

我想在gnuplot中将函数打印到文件。 这是一个最小的示例:

set print 'test.txt'
a=2
y(x)=sin(x)
set xrange [-5:5]
plot y(x)
print a
print y(x)

除最后一行外,所有线路都可以工作,这给出了一个错误:未定义的变量:x。 绘图命令如何工作,而不是打印命令。

如何将y(x)函数的x-和y-data打印到txt-file?

I would like to print a function to a file in gnuplot.
Here is a minimal example:

set print 'test.txt'
a=2
y(x)=sin(x)
set xrange [-5:5]
plot y(x)
print a
print y(x)

All lines do work, besides the last line, which gives an error: undefined variable:x.
How is it possible that the plot command works, but not the print command.

How can I print the x- and y-data of the y(x) function to a txt-file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风情万种。 2025-02-09 20:23:47

您要查找的命令是SET TABLE

a=2
y(x)=sin(x)
set xrange [-5:5]
set table 'test.txt'
plot y(x) title "a=2"
unset table

文件text.txt现在包含:

# Curve 0 of 1, 100 points
# Curve title: "a=2"
# x y type
-5  0.958924  i
-4.89899  0.982641  i
-4.79798  0.996339  i
-4.69697  0.999881  i
-4.59596  0.99323  i
-4.49495  0.976453  i
-4.39394  0.949722  i
-4.29293  0.913309  i
-4.19192  0.867586  i
-4.09091  0.813018  i
...

The command you are looking for is set table.

a=2
y(x)=sin(x)
set xrange [-5:5]
set table 'test.txt'
plot y(x) title "a=2"
unset table

The file text.txt now contains:

# Curve 0 of 1, 100 points
# Curve title: "a=2"
# x y type
-5  0.958924  i
-4.89899  0.982641  i
-4.79798  0.996339  i
-4.69697  0.999881  i
-4.59596  0.99323  i
-4.49495  0.976453  i
-4.39394  0.949722  i
-4.29293  0.913309  i
-4.19192  0.867586  i
-4.09091  0.813018  i
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文