【问题标题】:gnuplot isstring function available?gnuplot isstring 函数可用吗?
【发布时间】:2016-11-09 16:08:57
【问题描述】:

我正在挖掘 gnuplot 脚本。我在处理变量方面遇到了麻烦。

我的计算变量有时是实数,有时是字符串(“outrange”等)。

下一步我想在一些计算后将它们放入一个长字符串,但我做不到。

例如,

my_return_var="1.2 3.4 5 outrange 9 20 3 4"
newstr=""
do for [tmp in my_return_var]{
    newstr=newstr.sprintf("%7.3f ",tmp*4)
    print newstr
}

因为第四个值是“outrange”,sprintf返回错误:f_sprintf:尝试用数字格式打印字符串值

因此,如果 gnuplot 有一个检查输入是否为字符串并返回 1 或 0 的函数,如 C 中的 isstring(),我可以跳过这个。

还有其他想法吗?

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    不,gnuplot 没有字符串检查功能。但是您可以使用eqne 进行字符串比较以检查固定占位符:

    my_return_var="1.2 3.4 5 outrange 9 20 3 4"
    newstr=""
    do for [tmp in my_return_var] {
        if (tmp ne "outrange") {
            newstr=newstr.sprintf("%7.3f ",tmp*4)
            print newstr
        }
    }
    

    【讨论】:

    • 感谢您,这既简单又出色。我没想到。
    猜你喜欢
    • 2018-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多