[MATLAB]将mat格式文件批量转换为二进制数据文件
(2017-03-21 17:23:43)
|
|
|
1 |
%功能:批量读取文件夹内mat文件,并转换为bin格式。matlab版本:R2015b
|
|
2 |
clear;clc;
|
|
3 |
start_path
=
'';
|
|
4 |
dialog_title
=
'打开AD数据文件夹';
|
|
5 |
folder_name
=
uigetdir(start_path,dialog_title);
|
|
6 |
cd(folder_name);
|
|
7 |
listing
=
dir(folder_name);
|
|
8 |
for ilisting
=
1:numel(listing)
|
|
9 |
if listing(ilisting).isdir,
continue,
end
%忽略目录文件
|
|
10 |
[pathstr,name,ext]
=
fileparts(listing(ilisting).name);
|
|
11 |
if ~strcmp(ext,'.mat'),
continue,
end;
%忽略不符合的文件类型
|
|
12 |
binFlieName
=
strcat(name,'.bin');
%生成二进制文件名
|
|
13 |
fileID
=
fopen(binFlieName,'wb');
|
|
14 |
data
=
load(listing(ilisting).name);
%data为struct类型
|
|
15 |
fieldNames
=
fieldnames(data);
|
|
16 |
eval(['A
= data.',fieldNames{1},';']);
%执行A
= data.fieldnames(A);
|
|
17 |
machineformat
=
'native';
|
|
18 |
fwrite(fileID,
A,
'double',
0,
machineformat);
|
|
19 |
fclose(fileID);
|
|
20 |
end
|
|
喜欢
0
赠金笔
加载中,请稍候......