首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法打开matlab文件

问无法打开matlab文件
EN

Stack Overflow用户
提问于 2015-11-13 12:40:41
回答 3查看 3.8K关注 0票数 5

我有一个".mat“文件,据说包含一个30720000x4双矩阵(来自加速度计的值)。当我试图用Matlab中的"Import“打开这个文件时,我会得到以下错误:

代码语言:javascript
复制
Error using load
Can't read file F:\vibration_exp_2\GR_UB50n\bearing1\GR_UB50n_1_2.mat.

Error using load
Unknown text on line number 1 of ASCII file
F:\vibration_exp_2\GR_UB50n\bearing1\GR_UB50n_1_2.mat
"MATLAB".

Error in uiimport/runImportdata (line 456)
                    datastruct = load('-ascii', fileAbsolutePath);

Error in uiimport/gatherFilePreviewData (line 424)
        [datastruct, textDelimiter, headerLines]= runImportdata(fileAbsolutePath,
        type);

Error in uiimport (line 240)
[ctorPreviewText, ctorHeaderLines, ctorDelim] = ...

文件大小为921 my,与打开的其他文件相同。我还尝试使用python打开文件,但没有成功。有什么建议吗?我使用MATLAB R2013b。

更多信息:

文件是如何创建的:

代码语言:javascript
复制
%% acquisition of vibration data
% input:
% sample rate in Hz (max. 51200 Hz, should be used as bearing 
% faults are high-frequent)
% time in seconds, stating the duration of the measurement 
% (e.g. 600 seconds = 10 minutes)
% filename for the file to be saved
%
% examples:
% data = DAQ(51200, 600, 'NF1_1.mat'); 
% data = DAQ(51200, 600, 'NF1_2.mat'); 
function data = DAQ(samplerate,time,filename) 

s = daq.createSession('ni'); % Creates the DAQ session
%%% Add the channels as accelerometer channels (meaning IEPE is turned on)
s.addAnalogInputChannel('cDAQ1Mod1','ai0','Accelerometer'); 
s.addAnalogInputChannel('cDAQ1Mod1','ai1','Accelerometer'); 
s.addAnalogInputChannel('cDAQ1Mod1','ai2','Accelerometer'); 
s.addAnalogInputChannel('cDAQ1Mod1','ai3','Accelerometer'); 
%s.addAnalogInputChannel('cDAQ1Mod2','ai0','Accelerometer'); 

s.Rate = samplerate;
s.NumberOfScans = samplerate*time; 
%%% Defining the Sensitivities in V/g
s.Channels(1).Sensitivity = 0.09478; %31965, top outer
s.Channels(2).Sensitivity = 0.09531; %31966, back outer
s.Channels(3).Sensitivity = 0.09275; %31964, top inner
s.Channels(4).Sensitivity = 0.09363; %31963, back inner

data = s.startForeground(); %Acquiring the data

save(filename, 'data');

更多信息:

当我使用一个简单的文本编辑器打开文件时,我可以看到许多没有意义的字符(​),但也看到了第一行:

Matlab5.0 MAT-FILE,平台: PCWIN64,创建于:清华4月30日16:29:07 2015

更多信息:文件本身:2.mat?dl=0,它是921 It。

编辑:

如何恢复我的数据?

我尝试过这,但是内存错误。我也尝试过这,但是它没有起作用。

EN

回答 3

Stack Overflow用户

发布于 2015-11-21 21:36:52

恐怕我不能在你所知道的基础上增加很多好消息,但还没有被提及。

无法加载..mat文件的原因是数据被破坏。使其“不可恢复”的是内部存储的方式。确切的格式是在文件格式文件中指定的。因此,我决定手动构建一个简单的读取器,专门读取.mat文件。

有道理的是,splitmat.m不能恢复任何东西,因为它将数据基本分割成块,每个块存储一个变量,但是在这种情况下,只存储了一个变量,因此只有一个块,这恰好是损坏的块。

在这种情况下,数据存储为一个miCOMPRESSED,这是一个普通的使用gzip压缩的matlab数组。(顺便说一句,这似乎不太适合“随机”振动数据。)这可能解释了以前关于较小文件大小的注释,然后解释了完整的数据,因为文件大小与内部存储的值非常匹配。

我提取了压缩的存档,并试图以各种方式解压缩它。基本上,它是一个没有头的“.gz”,可以手动追加。不幸的是,在数据集开始附近似乎有一个损坏的块。我绝不是gzip方面的专家,但据我所知,字典(或解密密钥)是动态存储的,这使得所有数据从块被损坏的那一点起就毫无用处。如果您真的很渴望,那么即使在数据被破坏的地方,似乎也有一种恢复数据的方法,但是该方法是大规模的时间消耗。另外,验证这些部分的数据的唯一方法是手动检查,在您的情况下,这可能会非常困难。

下面是我用来解压缩..gz文件的代码,所以如果您想尝试一下,这可能会让您开始工作。如果您设法解密数据,您可以按照MAT-文件格式,13f中所描述的那样读取数据。

代码语言:javascript
复制
corrupted_file_id = fopen('corrupt.mat','r');
%% some header data
% can be skipped replacing this block with
% fread(id,132);

%header of .mat file
header_text = char(fread(corrupted_file_id,116,'char')');
subsystem_data_offset = fread(corrupted_file_id,8,'uint8');
version = fread(corrupted_file_id,1,'int16');
endian_indicator = char(fread(corrupted_file_id,2,'int8')');
data_type = fread(corrupted_file_id,4,'uint8'); 
%data_type is 15, so it is a compressed matlab array


%% save te content
data_size = fread(corrupted_file_id,1,'uint32');
gz_file_id = fopen('compressed_array.gz','w');
% first write a valid gzip head
fwrite(gz_file_id,hex2dec('1f8b080000000000'),'uint64',0,'b');

% then write the data sequentialy 
step = 1:1e3:data_size;% 1MB steps
for idx = step
fwrite(gz_file_id,fread(corrupted_file_id,1e3,'uint8'));
end
step = step(end):data_size;% 1B steps
for idx = step
    fwrite(gz_file_id,fread(corrupted_file_id,1,'uint8'));
end
fclose(gz_file_id);
fclose(corrupted_file_id);
票数 4
EN

Stack Overflow用户

发布于 2015-11-13 14:25:01

要真正回答这个问题,我的建议是首先确保文件没有问题。文件交换上的这个工具显然知道如何从版本.MAT (R8)开始诊断损坏的R8文件:

http://www.mathworks.com/matlabcentral/fileexchange/6893-matcat-mat-file-corruption-analysis-tool

票数 1
EN

Stack Overflow用户

发布于 2015-11-20 13:21:09

文件的大小(索引超出范围)似乎是个问题。应该读取Octave文件的.mat给出了错误

代码语言:javascript
复制
memory exhausted or requested size too large for range of Octave's index type

为了找出问题所在,您可能需要在MatLab之外编写一个测试程序,在那里您可以更好地控制内存管理。示例是这里,包括如何在您自己的平台上构建它们的说明。这些独立程序可能没有相同的内存问题。matdgns.c程序专门用于检查.mat文件中的错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33692996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档