当数组未在特定行定义时,Gnuplot 会抱怨 ')'

问题描述 投票:0回答:1

我使用的 gnuplot 脚本在执行脚本的最后一行时会产生错误。我没有看到这条线有任何问题。错误是:')'预期。如果将行 数组 M_x_N[numRecord] 移动到该行之前
统计 N 使用 (M_x_N[int($0+1)] = N[int($0+1)]*M[int($0+1)]) name "M_x_N" nooutput
没有错误。怎么了?

我正在使用 QT 终端,gnuplot 5.4 补丁级别 8。操作系统是 Windows 10。

脚本是:

reset session
set encoding utf8
set datafile separator comma
cd 'C:\Users\smallz4'
corpusFile = "lz4_silicia_corpus.txt_4096.csv"
stats corpusFile nooutput
numRecord = STATS_records
chunkSize = numRecord-15.0
bias = 2048.0

array M[numRecord]
array N[numRecord]
array M_x_N[numRecord]

stats corpusFile using (M[int($0+1)] = $1) name "M" nooutput
stats corpusFile using (N[int($0+1)] = $2) name "N" nooutput

stats N using (M_x_N[int($0+1)] = N[int($0+1)]*M[int($0+1)]) name "M_x_N" nooutput
gnuplot
1个回答
0
投票

好吧,我花了一段时间才弄清楚发生了什么事。由于我还不明白的原因,最终数组的名称似乎导致了错误。

help variables
说:

有效名称与大多数编程语言中的相同:它们必须 以字母开头,但后续字符可以是字母、数字、 或“_”。

因此,

M_x_N
应该是一个有效的变量或数组名称。至少,我还没有找到一个声明说数组名称不允许使用
_

通过以下最小的、完整的示例,我可以重现您的错误。现在,我想我明白你的意思了。 显然,数组定义的顺序和 stats 命令很重要。

脚本:

(此脚本将因您的错误而失败) ### strange behaviour with setting arrays and using stats reset session $Data <<EOD 1 10 2 20 3 30 4 40 EOD stats $Data u (c=$0+1) nooutput # get the number of rows into c array M[c] array M_x_N[c] stats $Data u (M[int($0+1)] = $1) name "M" nooutput stats $Data u (M_x_N[int($0+1)] = $2) name "M_x_N" nooutput ### end of script

但是,如果将顺序更改为以下内容,它就会起作用。

array M[c] stats $Data u (M[int($0+1)] = $1) name "M" nooutput array M_x_N[c] stats $Data u (M_x_N[int($0+1)] = $2) name "M_x_N" nooutput

具有原始序列的另一个版本,即首先所有数组定义,然后所有 
stats

命令将按预期工作,如果您将数组

M_x_N
的名称更改为
MxN
array M[c]
array MxN[c]

stats $Data u (M[int($0+1)] = $1) name "M" nooutput
stats $Data u (MxN[int($0+1)] = $2) name "MxN" nooutput

所以,我的结论是 
M_x_N

中的下划线在某种程度上弄乱了

stats
命令。我认为这是一个错误,或者也许其他人可以解释。
    

© www.soinside.com 2019 - 2024. All rights reserved.