在函数执行过程中,在 Matlab 中解压缩文本文件的最快方法是什么?
我想使用 textscan 函数扫描 Matlab 中文本文件的文本。在使用 fid = fopen('C:\path') 打开文本文件之前,我需要先解压缩文件。这些文件的扩展名是:*.gz
我需要分析数千个文件,高性能非常重要。
我有两个想法: (1) 使用外部程序并在Matlab中从命令行调用它 (2) 使用Matlab“zip”工具箱。我听说过gunzip,但不知道它的性能如何。
有谁知道如何从 Matlab 中尽快解压这些文件?
谢谢!
I would like to scan text of textfiles in Matlab with the textscan function. Before I can open the textfile with fid = fopen('C:\path'), I need to unzip the files first. The files have the extension: *.gz
There are thousands of files which I need to analyze and high performance is important.
I have two ideas:
(1) Use an external program an call it from the command line in Matlab
(2) Use a Matlab 'zip'toolbox. I have heard of gunzip, but don't know about its performance.
Does anyone knows a way to unzip these files as quick as possible from within Matlab?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您始终可以尝试 Matlab unzip() 函数:
unzip
提取 zip 文件的内容
语法
unzip(zipfilename)
解压缩(压缩文件名,输出目录)
解压缩(网址,...)
filenames = unzip(...)
描述
unzip(zipfilename) 将 zipfilename 的存档内容提取到当前文件夹中并设置文件的属性,同时保留时间戳。如果现有文件的属性和所有权允许,它会覆盖与存档中的文件同名的任何现有文件。例如,对同一 zip 文件名重新运行解压缩的文件不会覆盖任何具有只读属性的文件;相反,unzip 会对此类文件发出警告。
在内部,它使用 Java 的 zip 库
org.apache.tools.zip
。如果您的 zip 存档中每个都包含许多文本文件,那么将其放入 Java 中并逐项提取它们可能会更快,而无需显式解压缩文件。查看 unzip.m 的源代码以获取一些想法,还有 Java 文档。You could always try the Matlab unzip() function:
unzip
Extract contents of zip file
Syntax
unzip(zipfilename)
unzip(zipfilename, outputdir)
unzip(url, ...)
filenames = unzip(...)
Description
unzip(zipfilename) extracts the archived contents of zipfilename into the current folder and sets the files' attributes, preserving the timestamps. It overwrites any existing files with the same names as those in the archive if the existing files' attributes and ownerships permit it. For example, files from rerunning unzip on the same zip filename do not overwrite any of those files that have a read-only attribute; instead, unzip issues a warning for such files.
Internally, this uses Java's zip library
org.apache.tools.zip
. If your zip archives each contain many text files it might be faster to drop down into Java and extract them entry by entry, without explicitly unzipped files. look at the source of unzip.m to get some ideas, and also the Java documentation.我发现 7zip-commandline(Windows) / p7zip(Unix) 有点为此速度更快。
[编辑]从一些快速测试来看,对gunzip进行系统调用似乎比使用MATLAB的本机gunzip更快。你也可以尝试一下。
只需编写一个模仿基本 MATLABgunzip 功能的新函数即可:
然后像使用gunzip 一样使用它:
使用 MATLAB 的
toc
计时器,我通过 6 个未压缩的 114MB ASCII 文件获得以下提取时间:gunzip:10.15s
太阳压缩:7.84s
I've found 7zip-commandline(Windows) / p7zip(Unix) to be somewhat speedier for this.
[edit]From some quick testing, it seems making a system call to gunzip is faster than using MATLAB's native gunzip. You could give that a try as well.
Just write a new function that imitates basic MATLAB gunzip functionality:
Then use it as you would use gunzip:
With MATLAB's
toc
timer, I get the following extraction times with 6 uncompressed 114MB ASCII files:gunzip: 10.15s
sunzip: 7.84s
效果很好,只需要对 Max 调用可执行文件的语法进行微小的更改。
worked well, just needed a minor change to Max's syntax calling the executable.