octave - regexp does not work as expected in Octave
问题描述
I have downloaded the "NYU Depth V2" dataset and toolbox from here. In the toolbox there is a script called get_synched_frames.m
. I do not have Matlab, so I have tried running it in Octave. Unfortunately, it does not work as expected.
The line
% Faster than matlab's Dir function for big directories and slow
% distributed file systems...
files = regexp(ls(sceneDir), '(\s+|\n)', 'split');
gives only
files =
{
[1,1] = a-1300302776.479149-3987628315.dump
}
but ls(sceneDir)
shows all files in the directory. Has anyone experienced this?
解决方案
The difference is probably not in regexp
, but in the return value of ls
. ls
does not behave the same way in Matlab and Octave when you capture its return value. Matlab's ls
returns a char row vector (single string as char) with multiple files listed in it as a multi-line string with embedded newlines; Octave's ls
returns a 2-D char array with one file per line. (IMHO Octave's format is better; it is very difficult to parse Matlab's ls
output in a reliably correct manner. (That regexp code is not adequate.))
You might just want this in Octave:
files = cellstr(ls(sceneDir));
推荐阅读
- node.js - 关于需要可选字段的 Joi 架构验证错误
- java - 自定义对象列表作为通用方法的参数
- android - 在 init 块中使用 postValue 时的 LiveData 单元测试错误
- google-app-engine - 应用引擎 urlfetch:如何使用 allow_truncate = true 获得完整响应?
- c# - C#如何在多个列表框中显示项目?
- javascript - Webpack 无法解析自定义 JS 文件
- python - 查询在查询浏览器中运行良好,但在 python 代码中运行良好
- reactjs - 在重定向组件(React.js)中传递道具没有按预期工作
- pdf - 如何读取 PDFsharp 返回的 UTF 元数据?
- javascript - 如何配置 Webpack 输出以仅包含特定捆绑包的某些选项