[英]GNU Octave: use textscan() function to read sequence of integers separated by a dot (.)
I am trying to read data from a file with dates in DAY.MONTH.YEAR format using the textscan(...) function. 我正在尝试使用textscan(...)函数从日期为DAY.MONTH.YEAR格式的文件中读取数据。 Below is a simple illustration of the problem. 下面是问题的简单说明。
This does not work as desired: 这不能按需工作:
u = textscan ('5.2.1975','%d.%d.%d')
u =
{
[1,1] = 5
[1,2] = 1975
[1,3] = 0
}
It seems textscan treats the 5.2 part as a decimal number and rounds it to 5. It returns the last number (1975) as the second element of u. 似乎textscan将5.2部分当作十进制数字并将其四舍五入。它返回最后一个数字(1975)作为u的第二个元素。
The conversion works as expected if the separator is not a dot: 如果分隔符不是点,那么转换将按预期进行:
u = textscan ('5*2*1975','%d*%d*%d')
u =
{
[1,1] = 5
[1,2] = 2
[1,3] = 1975
}
What do I need to change to make it work with the dot? 我需要更改使其与点一起使用吗?
Here is what I observe in Octave 4.0.3: 这是我在Octave 4.0.3中观察到的内容:
>> u = textscan ('5.2.1975','%d.%d.%d')
u =
{
[1,1] = 5
[1,2] = 2
[1,3] = 1975
}
So it seems that textscan
does exactly what you expect, in principle. 因此,原则上看来textscan
完全textscan
您的期望。
If you are seeing a different result: 如果您看到不同的结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.