如何拼接gnuplot数据块?循环拼接$Data报错解决
Gnuplot数据块拼接实现方法
你遇到的报错是因为gnuplot中数据块(以$开头的变量)不能像普通字符串那样用.运算符直接拼接,$Temp = $Temp . $Data这种写法不符合数据块的操作规则,才会抛出data block name must be followed by << EODmarker错误。
要实现数据块的循环拼接,正确的做法是利用set table的append模式,每次将临时数据块$Data的内容追加到目标数据块$Temp中,具体代码如下:
# 先初始化空的目标数据块$Temp set table $Temp plot NaN with table # 生成无数据的空数据块 unset table do for [selected_label in LABELS] { # 生成当前循环的临时数据$Data set table $Data plot '' index group using (@sel):(@corrected_volume) with table unset table # 将$Data的内容追加到$Temp set table $Temp append plot $Data using 1:2 with table unset table } # 输出拼接后的结果 print $Temp
关键说明:
set table $Temp append会开启数据块的追加模式,后续的plot命令会把数据追加到$Temp末尾,而不是覆盖原有内容- 初始化$Temp时用
plot NaN with table是为了创建一个合法的空数据块,避免第一次追加时出错
内容的提问来源于stack exchange,提问作者magfan
相关产品推荐
相关产品推荐

