如何在 Matlab 中打开 DBase 文件(.DBF)?
我已经通过 Google 搜索并通过 Matlab Central 进行搜索,但找不到任何直接在 Matlab 中打开 DBF 文件的方法。 TMW File Exchange 中有一些对 DBFREAD 函数的引用,但它不再可用。真的有问题吗?
我确实有数据库工具箱,但在那里找不到 dbf 支持。
我不想使用 Excel 或其他工具在 Matlab 之外转换文件,因为我有很多文件需要处理。 ODBC 也不好,我需要代码也能在 Mac 和 Unix 下工作。
请帮忙。
I've googled and searched through Matlab Central, but cannot find any way to open DBF files directly in Matlab. There are some references to DBFREAD function in TMW File Exchange, but it's not available anymore. Is it really a problem?
I do have Database toolbox, but could not find dbf support there.
I don't want to use Excel or other tools for converting files outside of Matlab, since I have a lot of files to process. ODBC also is not good, I need the code to work under Mac and Unix as well.
Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我联系了 DBFREAD 函数的作者 Brian Madsen,该函数已从 File Exchange 中删除,可能是因为 Mathworks 将在未来的某个版本中将此函数包含到 MATLAB 中。 Brian 好心允许我在这里发布这个函数。所有版权信息均保持不变。我只修改了第 33-38 行以允许 DBFREAD 读取工作目录之外的文件。
更新
如果输入参数中的位数不同,STR2DOUBLE2CELL 子函数有时无法正常工作(请参阅 此讨论)。
这是我的 STR2DOUBLE2CELL 版本:
I contacted with Brian Madsen, the author of DBFREAD function, which was deleted from File Exchange, probably because The Mathworks is going to include this function into MATLAB in some future release. Brian kindly gave me permission to publish this function here. All copyright information left intact. I only modified lines 33-38 to allow DBFREAD to read file outside working directory.
UPDATE
STR2DOUBLE2CELL subfunction sometimes works incorrectly if number of digits in the input parameter is different (see this discussion).
Here is my version of STR2DOUBLE2CELL:
在我看来,你有两个选择:
方法 1:使用 ODBC 读取 dBASE 文件:
这需要数据库工具箱
'dBASE Files' 是 ODBC 数据源名称 (DSN)(我相信默认情况下随 MS Office 安装)。它使用当前目录来查找 .dbf 文件。
或者,您可以使用无 DSN 的连接字符串,例如:
如果这给您带来麻烦,请尝试使用 FoxPro ODBC 驱动程序。
对于 Linux/Unix,可以执行相同的操作。快速搜索发现了这些:
方法 2 :直接使用库读取/写入 .dbf 文件
SVConsulting 提供了一个免费的 Java 库,它允许您读取/写入 DBF 文件:JDBF。 (更新:链接似乎已失效,请使用Wayback Machine 来访问它)
您可以直接从 MATLAB 使用 Java 类。请参阅文档了解具体操作方法。
The way I see it, you have two options:
Method 1: use ODBC to read the dBASE files:
This requires the database toolbox
'dBASE Files' is an ODBC Data Source Name (DSN) (I believe its installed by default with MS Office). It uses the current directory to look for .dbf files.
Or maybe you can use a DSN-less connection string with something like:
if this gives you trouble, try using the FoxPro ODBC Driver instead..
For Linux/Unix, the same thing could be done. A quick search revealed these:
Method 2: read/write .dbf files directly with a library
There's a Java library available for free from SVConsulting, that allows you to read/write DBF files: JDBF. (UPDATE: link seems to be dead, use Wayback Machine to access it)
You can use Java classes directly from MATLAB. Refer to the documentation to see how.
如果您只对数值感兴趣,请尝试 xlsread 命令。
If you are interested only in numerical values, try xlsread command.