gnuplot - splitting a number into the integer and decimal parts GNUPLOT
问题描述
Is there any way to split a number into its integer and decimal parts?
I've tried the int() "function":
int(5.5) = 5.
But I've got no idea how do I get the decimal?
Example:
(I have)
a = 12.34
(I want)
b = 12
c = 34
a = 12.34
b = int(a)
c = ????
Thanks!!!!
(Update)
My specific problem, here we have (thanks again for the support)
I have a set of data, with different blocks. For each block, I want to make the same plot. The title of the plot and the name of the output png depends on the block.
With this goal in mind I've created a loop
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}"
}
The problem I have is that I only can concatenate using the dot if the value is an integer. I get this error:
internal error : STRING operator applied to undefined or non-STRING variable
解决方案
If you want to include a float number into a title or a file name use the string formatting via sprintf()
, check help sprintf
and help format specifiers
.
a = 1.234
myFile = sprintf("MyFileName_%g_MoreParameters.png",a)
print myFile
Result:
MyFileName_1.234_MoreParameters.png
推荐阅读
- python - Tkinter mainloop()在关闭窗口后没有退出
- javascript - 我试图在 Electron.js 中单击按钮时打开新窗口,但未捕获 ReferenceError: require is not defined
- c - 我在使用 strcmp 时遇到问题。由于某种原因,它检测到了错误的单词,但仍然继续使用代码
- powershell - 尝试在列表上使用 Import-Clixml 时
,返回值为 System.Object - javascript - 作为有序树的产品选择
- android - 就地修改 MediaStore 的外部图像文件的最佳做法是什么?
- javascript - JavaScript 递归识别最后一个元素
- python - 如何使用组均值填充 df 中的 nan 值?
- swift - 具有可观察对象的类已被用于未初始化
- python - Kivy ImageButton 填满整个屏幕