将数据文件中的注释值存储在gnuplot中 [英] store commented value from data file in gnuplot

查看:65
本文介绍了将数据文件中的注释值存储在gnuplot中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个数据文件output_k,其中k是一个数字.文件看起来像

I have multiple data files output_k, where k is a number. The files look like

    #a=1.00 b = 0.01
    # mass  mean    std  
    0.2 0.0163  0.0000125
    0.4 0.0275  0.0001256

现在,我需要检索ab的值并将它们存储在变量中,因此我可以将它们用于标题或函数输入等.遍历文件夹中的文件是可行的.但是我需要一些帮助来读取参数ab.这就是我到目前为止所拥有的.

Now I need to retrieve the values of a and b and to store them in a variable, so I can use them for the title or function input etc. The looping over the files in the folder works. But I need some help with reading out the the parameters a and b. This is what i have so far.

    # specify the number of plots
    plot_number = 100
    # loop over all data files
    do for [i=0:plot_number] {
    a = TODO
    b = TODO
    #set terminal
    set terminal postscript eps size 6.4,4.8 enhanced color font 'Helvetica,20' linewidth 2
    set title "Measurement \n{/*0.8 A = a, B = b}"

    outFile=sprintf("plot_%d.eps", i)
    dataFile=sprintf("output_%d.data", i)

    set output outFile
    plot dataFile using 1:2:3 with errorbars lt 1 linecolor "red", f(a,b)

    unset output
    }

我正在使用gnuplot for Windows.

I am working with gnuplot for windows.

推荐答案

如果您使用的是Unixoid系统,则可以使用system获取标准命令行工具(headsed)的输出,再次允许从文件中提取所述值:

If you are on a Unixoid system, you can use system to get the output of standard command line tools, namely head and sed, which again allow to extract said values form the files:

a = system(sprintf("head -n 1 output_%i.data | sed \"s/#a=//;s/ b .*//\"", i))
b = system(sprintf("head -n 1 output_%i.data | sed \"s/.*b = //\"", i))

这假设问题中所有行的前导空格实际上是格式错误.

This assumes that the leading spaces to all lines in your question are actually a formatting mistake.

这篇关于将数据文件中的注释值存储在gnuplot中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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