为什么 sscanf 在这里表现奇怪?

Why does sscanf perform strangely here?

我在 Matlab 中使用 sscanf,它工作正常,除非使用特定的字符组合:

sscanf('2015.10.07-00:07:01', '%i.%i.%i-%i:%i:%i')

return数组

ans =

        2015
          10
           7
           0
           7
           1

但是

sscanf('2015.10.07-00:08:01', '%i.%i.%i-%i:%i:%i')

returns

ans =

        2015
          10
           7
           0
           0

请注意,通过 0207 and/or 08 更改为 01 也是我所期望的 return。这是巧合吗,我实际上读错了这行,还是这里发生了什么奇怪的事情?

根据 the documentation,它似乎被读取为十六进制。我需要使用 %d 而不是 %i 来强制以 10 为基数进行解释。

我试试这个

sscanf('2015.10.08-00:07:01', '%i.%i.%i-%i:%i:%i')

return

2015
10
0

根据 sscanf 上的文档,它被读取为基数 8 (00-07),因为初始值为 0。我认为这会导致错误,因为 08 被读取为 0 并停止读取字符串的其余部分。