2015-02-06 148 views
1

我有一个与许多对象和标签的情节。所以我想用循环来简化srcipt。但我不知道如何应对变数。我定义变量遵循Gnuplot循环连续变量

V1 = 10 
V2 = 20 
V3 = 23 
... 
LABEL1 = a 
LABEL2 = b 
... 

循环看起来应该像

set for [i=1:15] label i at V(i),y_label LABEL(i) 

这个符号会导致错误编译脚本。在gnuplot中定义这样一个循环是否可行?如果是这样,我该怎么做? 感谢您的帮助!

回答

1

您可以定义哪些格式的标签定义字符串的函数,并使用do循环计算字符串:

y_label = 0 
V1 = 10 
V2 = 20 
V3 = 23 
LABEL1 = "a" 
LABEL2 = "b" 
LABEL3 = "c" 

do for [i=1:3] { 
    eval(sprintf('set label %d at V%d,y_label LABEL%d', i, i, i)) 
} 

或者,你可以用两个字符串进行迭代,用空格分开的话:

V = "10 20 23" 
LABEL = "a b c" 
set for [i=1:words(V)] label i at word(V, i),y_label word(LABEL, i) 

注意,这GNUPLOT 5.0还必须使用引号一起举办若干个字作为一个项目一些有限的支持:

V = "10 20 25" 
LABEL = "'first label' 'second label' 'third one'" 
set for [i=1:words(V)] label i at word(V, i),y_label word(LABEL, i) 

enter image description here

+0

谢谢!有用! – Froop 2015-02-06 10:19:32