将数字拆分为整数和小数部分 GNUPLOT
splitting a number into the integer and decimal parts GNUPLOT
有什么方法可以把一个数字分成整数和小数部分吗?
我试过 int() “函数”:
int(5.5) = 5.
但是我不知道如何得到小数?
示例:
(我有)
一=12.34
(我要)
b = 12
c = 34
a = 12.34
b = int(a)
c = ????
谢谢!!!!
(更新)
我的具体问题,这里有(再次感谢支持)
我有一组数据,有不同的块。对于每个块,我想绘制相同的图。
图的标题和输出 png 的名称取决于块。
考虑到这个目标,我创建了一个循环
do for [j=0:int(A_blocks-2)]{
i=0 + 0.4*j
set output 'Mz_NMcs5000_Hext'.i.'_JC1_JSn05_JIntn05_R11_tSh2.png'
set title "H = '.i.' J_C = 1 J_S = J_{Int} = - 0.5"
plot filename index j using 1:5 w lp pt 5 lt rgb "black" title "Mag_T", "" index j u 1:20 w lp pt 9 lt rgb "red" title "Mag_{Int-S}"
}
我遇到的问题是,如果值是整数,我只能使用点连接。我收到此错误:
internal error : STRING operator applied to undefined or non-STRING variable
如果要在标题或文件名中包含浮点数,请使用 sprintf()
中的字符串格式,选中 help sprintf
和 help format specifiers
。
a = 1.234
myFile = sprintf("MyFileName_%g_MoreParameters.png",a)
print myFile
结果:
MyFileName_1.234_MoreParameters.png
你的问题好像变了,但原问题的答案是
gnuplot> a = 5.5555555555555
gnuplot> b = a - floor(a)
gnuplot> print b
0.5555555555555
有什么方法可以把一个数字分成整数和小数部分吗?
我试过 int() “函数”:
int(5.5) = 5.
但是我不知道如何得到小数?
示例:
(我有)
一=12.34
(我要)
b = 12
c = 34
a = 12.34
b = int(a)
c = ????
谢谢!!!!
(更新)
我的具体问题,这里有(再次感谢支持)
我有一组数据,有不同的块。对于每个块,我想绘制相同的图。 图的标题和输出 png 的名称取决于块。
考虑到这个目标,我创建了一个循环
do for [j=0:int(A_blocks-2)]{
i=0 + 0.4*j
set output 'Mz_NMcs5000_Hext'.i.'_JC1_JSn05_JIntn05_R11_tSh2.png'
set title "H = '.i.' J_C = 1 J_S = J_{Int} = - 0.5"
plot filename index j using 1:5 w lp pt 5 lt rgb "black" title "Mag_T", "" index j u 1:20 w lp pt 9 lt rgb "red" title "Mag_{Int-S}"
}
我遇到的问题是,如果值是整数,我只能使用点连接。我收到此错误:
internal error : STRING operator applied to undefined or non-STRING variable
如果要在标题或文件名中包含浮点数,请使用 sprintf()
中的字符串格式,选中 help sprintf
和 help format specifiers
。
a = 1.234
myFile = sprintf("MyFileName_%g_MoreParameters.png",a)
print myFile
结果:
MyFileName_1.234_MoreParameters.png
你的问题好像变了,但原问题的答案是
gnuplot> a = 5.5555555555555
gnuplot> b = a - floor(a)
gnuplot> print b
0.5555555555555