无法打开matlab文件

时间:2015-11-13 12:40:42

标签: matlab

我有一个“.mat”文件,据说包含[30720000x4 double]矩阵(来自加速度计的值)。当我尝试在Matlab中使用“导入数据”打开此文件时,出现以下错误:

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] = ...

filesize是921MB,与我打开的其他文件相同。我也尝试使用python打开文件,但没有成功。有什么建议?我使用MATLAB R2013b。

更多信息:

文件是如何创建的:

%% 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');

更多信息:

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

  

MATLAB 5.0 MAT-FILE,平台:PCWIN64,创建时间:4月30日星期四   2015年16:29:07

更多信息: 文件本身:https://www.dropbox.com/s/r7mavil79j47xa2/GR_UB50n_1_2.mat?dl=0 它是921MB。

修改

如何恢复数据?

我尝试了this,但是出现了内存错误。 我也试过了this,但它没有用。

3 个答案:

答案 0 :(得分:4)

我担心我不能在你已经知道的事情上添加许多好消息,但尚未提及。

.mat文件无法加载的原因是数据损坏。什么使它“不可恢复”是它在内部存储的方式。确切的格式在MAT-File Format Documentation中指定。所以我决定手动构建一个简单的阅读器来专门读取你的.mat文件。

有意义的是,splitmat.m无法恢复任何内容,因为它会将数据基本上分成块,每个块一个存储变量,但是在这种情况下只存储一个变量,因此只有一个大块,恰好是腐败的。

在这种情况下,数据存储为miCOMPRESSED,这是使用gzip压缩的普通matlab数组。 (作为旁注,这似乎不适合'随机'振动数据。)这可能解释了之前关于文件大小小于完整数据的评论,因为文件大小与内部存储的值完全匹配。

我解压缩了压缩档案并试图以各种方式解压缩它。基本上它是没有标题的'.gz',可以手动追加。不幸的是,在数据集的开头附近似乎存在损坏的块。我绝不是gzip的专家,但据我所知,字典(或解密密钥)是动态存储的,这使得所有数据从块被破坏的点开始无用。如果你真的很渴望,似乎a way to recover data甚至落后于数据被破坏的地方,但这种方法耗费大量时间。验证这些部分数据的唯一方法是手动检查,在您的情况下可能证明非常困难。

下面是我用来提取.gz文件的代码,所以如果你想尝试一下,这可能会让你开始。如果您设法解密数据,则可以按照MAT-File Format,13f。

中的说明进行阅读。
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);

答案 1 :(得分:1)

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

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

答案 2 :(得分:0)

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

memory exhausted or requested size too large for range of Octave's index type

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

相关问题