Gnuplot不使用stats计算统计信息。

huangapple go评论111阅读模式
英文:

Gnuplot does not calculate statistics with stats

问题

在以下代码中,stats命令失败。Gnuplot假定$Data中没有有效数据点,因此不计算记录数(STATS_records)。需要更改什么来计算统计信息?

reset session

$Data <<EOD
AK	lA	rA	lH	rH
4	8820	3861	4954.7	2093.5
4	6294.4	2604.3	4251.9	1733.1
4	8671.5	3271.7	4912	2075.7
4	9447.3	3454.1	5054.1	2220.5
4	8070.9	2919.6	4434.8	1920.8
2	8951.2	3548.1	4838.1	1946.2
4	7809.1	2573.1	3913	1723.8
4	7985.3	3228.1	4816.9	1897
2	9239	3970.7	5011.8	2161
2	7549.9	3104.6	3854.8	1681.7
2	8706.2	3167.6	4713.1	2191.5
4	10121.5	3890.7	5599.5	2377.3
4	9153.3	3114.2	4890.2	1930
4	8327.5	3741.6	4793.4	2140.1
3	7091.6	3013.2	4053.9	2224.8
3	6878.2	3298.8	4238.6	1900
2	6940.4	2751.3	3810.6	1581.8
2	7232.9	3296.6	4342	1540.1
3	8722	3851.3	5646.5	2213
4	7723.4	3541.9	4588.6	2380.7
2	8272.8	3184.3	5262.9	1914.6
2	6798.3	2685.9	3208	1665.5
4	7685.6	3132.5	3486.7	1457.2
2	6820.9	2677.6	4388.6	2223
4	6980.2	3062.4	4375.9	1681.9
EOD

LABELS          = 'lA rA lH rH'
DATA_BLOCKS     = 'V1 V2'
GROUP_LABELS    = '2 3 4'
GROUP_COLUMNS   = 'AK'

do for [selected_label in LABELS] {
    do for [i=1:words(DATA_BLOCKS)] {
        do for [j=1:words(GROUP_LABELS)] {
            stats $Data index word(DATA_BLOCKS, i) using (((column(GROUP_COLUMNS) == j) ? 1.0 : NaN) * column(selected_label)) 
            print STATS_records
        }
    }

    pause -1
    pause -1
}

第45行:警告:文件中未找到有效数据点
第47行:未定义的变量:STATS_records


<details>
<summary>英文:</summary>
In the following code, the stats command fails. Gnuplot assumes that there are no valid points in $Data and therefore does not calculate the number of records (STATS_records). What needs to be changed to calculate the statistics?

reset session

$Data <<EOD
AK lA rA lH rH
4 8820 3861 4954.7 2093.5
4 6294.4 2604.3 4251.9 1733.1
4 8671.5 3271.7 4912 2075.7
4 9447.3 3454.1 5054.1 2220.5
4 8070.9 2919.6 4434.8 1920.8
2 8951.2 3548.1 4838.1 1946.2
4 7809.1 2573.1 3913 1723.8
4 7985.3 3228.1 4816.9 1897
2 9239 3970.7 5011.8 2161
2 7549.9 3104.6 3854.8 1681.7
2 8706.2 3167.6 4713.1 2191.5
4 10121.5 3890.7 5599.5 2377.3
4 9153.3 3114.2 4890.2 1930
4 8327.5 3741.6 4793.4 2140.1
3 7091.6 3013.2 4053.9 2224.8
3 6878.2 3298.8 4238.6 1900
2 6940.4 2751.3 3810.6 1581.8
2 7232.9 3296.6 4342 1540.1
3 8722 3851.3 5646.5 2213
4 7723.4 3541.9 4588.6 2380.7
2 8272.8 3184.3 5262.9 1914.6
2 6798.3 2685.9 3208 1665.5
4 7685.6 3132.5 3486.7 1457.2
2 6820.9 2677.6 4388.6 2223
4 6980.2 3062.4 4375.9 1681.9
EOD

LABELS = 'lA rA lH rH'
DATA_BLOCKS = 'V1 V2'
GROUP_LABELS = '2 3 4'
GROUP_COLUMNS = 'AK'

do for [selected_label in LABELS] {
do for [i=1:words(DATA_BLOCKS)] {
do for [j=1:words(GROUP_LABELS)] {
stats $Data index word(DATA_BLOCKS, i) using (((column(GROUP_COLUMNS) == j) ? 1.0 : NaN) * column(selected_label))
print STATS_records
}
}

pause -1
pause -1

}

line 45: warning: No valid data points found in file
line 47: undefined variable: STATS_records


</details>
# 答案1
**得分**: 1
gnuplot无法找到块`V1`和`V2`(请查看您的`stats`命令`... index word(DATA_BLOCKS, i)...`)。
因此,如果您的数据看起来像这样,脚本可能会按照您的期望工作。
```plaintext
$Data &lt;&lt;EOD
# V1
AK  lA  rA  lH  rH
4   9447.3  3454.1  5054.1  2220.5
4   8070.9  2919.6  4434.8  1920.8
2   8951.2  3548.1  4838.1  1946.2
4   7809.1  2573.1  3913    1723.8
3   7985.3  3228.1  4816.9  1897
2   9239    3970.7  5011.8  2161
# V2
AK  lA  rA  lH  rH
2   8706.2  3167.6  4713.1  2191.5
4   10121.5 3890.7  5599.5  2377.3
4   9153.3  3114.2  4890.2  1930
3   7091.6  3013.2  4053.9  2224.8
3   6878.2  3298.8  4238.6  1900
2   6940.4  2751.3  3810.6  1581.8
EOD

附加信息:

您可以按名称或按索引循环:

do for [GROUP_LABEL in GROUP_LABELS] { ... }   # 按名称循环

do for [j=1:words(GROUP_LABELS)] { ... }       # 按索引循环

由于您的GROUP_LABELS实际上是数字,gnuplot会将它们转换为数字,因此您可以使用字符串比较eq或数字比较(==

... strcol(GROUP_COLUMNS) eq GROUP_LABEL ...         # 按名称循环时

... column(GROUP_COLUMNS) == word(GROUP_LABELS,j)    # gnuplot将字符串word(...)转换为数字
英文:

gnuplot is simply not finding the blocks V1 and V2 (see your stats command ... index word(DATA_BLOCKS, i)...)
So, if your data would look e.g. like this, the script probably would do what you expect.

$Data &lt;&lt;EOD
# V1
AK  lA  rA  lH  rH
4   9447.3  3454.1  5054.1  2220.5
4   8070.9  2919.6  4434.8  1920.8
2   8951.2  3548.1  4838.1  1946.2
4   7809.1  2573.1  3913    1723.8
3   7985.3  3228.1  4816.9  1897
2   9239    3970.7  5011.8  2161
# V2
AK  lA  rA  lH  rH
2   8706.2  3167.6  4713.1  2191.5
4   10121.5 3890.7  5599.5  2377.3
4   9153.3  3114.2  4890.2  1930
3   7091.6  3013.2  4053.9  2224.8
3   6878.2  3298.8  4238.6  1900
2   6940.4  2751.3  3810.6  1581.8
EOD

Addition:

You can either loop by name or by index:

do for [GROUP_LABEL in GROUP_LABELS] { ... }   # loop by name
do for [j=1:words(GROUP_LABELS)] { ... }       # loop by index

Since your GROUP_LABELS are actually numbers, gnuplot will convert them into numbers, so you could use either string comparsion eq or number comparison (==)

... strcol(GROUP_COLUMNS) eq GROUP_LABEL ...         # when loop by name
... column(GROUP_COLUMNS) == word(GROUP_LABELS,j)    # gnuplot will convert the string word(...) into a number

huangapple
  • 本文由 发表于 2023年6月6日 15:49:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76412467.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定