在函数执行过程中,在 Matlab 中解压缩文本文件的最快方法是什么?

发布于 2024-08-22 03:40:32 字数 263 浏览 5 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

紅太極 2024-08-29 03:40:32

您始终可以尝试 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.

赠我空喜 2024-08-29 03:40:32

我发现 7zip-commandline(Windows) / p7zip(Unix) 有点为此速度更快。

[编辑]从一些快速测试来看,对gunzip进行系统调用似乎比使用MATLAB的本机gunzip更快。你也可以尝试一下。

只需编写一个模仿基本 MATLABgunzip 功能的新函数即可:

function [] = sunzip(完整文件名,output_dir)
if ~exist('output_dir','var'), output_dir = fileparts(完整文件名);结束

app_path = '/usr/bin/7za';
开关='e'; %提取文件忽略目录结构
选项 = ['-o' 输出目录];

system([app_path 切换选项 '_' 完整文件名]);

然后像使用gunzip 一样使用它:

sunzip('/data/time_1000.out.gz',tmp_dir);

使用 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:

function [] = sunzip(fullfilename,output_dir)
if ~exist('output_dir','var'), output_dir = fileparts(fullfilename); end

app_path = '/usr/bin/7za';
switches = ' e'; %extract files ignoring directory structure
options = [' -o' output_dir];

system([app_path switches options '_' fullfilename]);

Then use it as you would use gunzip:

sunzip('/data/time_1000.out.gz',tmp_dir);

With MATLAB's toc timer, I get the following extraction times with 6 uncompressed 114MB ASCII files:

gunzip: 10.15s
sunzip: 7.84s

痞味浪人 2024-08-29 03:40:32

效果很好,只需要对 Max 调用可执行文件的语法进行微小的更改。

system([app_path switches ' ' fullfilename options ]);

worked well, just needed a minor change to Max's syntax calling the executable.

system([app_path switches ' ' fullfilename options ]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文