简体   繁体   English

GNU Octave:使用textscan()函数读取由点(。)分隔的整数序列

[英]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: 如果您看到不同的结果:

  • in an older Octave release, you should upgrade your version of Octave and check again; 在较旧的Octave版本中,您应该升级Octave的版本并再次检查;
  • in a recent release, you should report this as a bug on the Octave bug tracker . 在最新版本中,您应该在Octave Bug Tracker上将其报告为Bug

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM