フィルターのクリア

How to convert a folder of .bin files into .mat files?

28 ビュー (過去 30 日間)
arun
arun 2016 年 10 月 19 日
コメント済み: Walter Roberson 2017 年 9 月 17 日
With the code below, I was able to read a folder containing .bin files.. in the end it converts all .bin file into a single .mat file which is not so easy to process... Can somebody provide me the code for converting each .bin file into .mat file( without changing the name) to be saved within the folder itself... Please tell me the importance of header files.. Whether i need it during processing steps...
% clear;close all;clc;
binPath = 'MSR Daily Activity 3D dataset\Depth';
for ai = 1:16
for si = 1:10
for ei = 1:2
%%%%%%%%%%%%%
%%%%%%%%%%%%%
[acsr,susr,exsr]=getsr(ai,si,ei);
%%%%%%getsr(ai,si,ei) convert ai,si,ei to double bits
%%%%%%for example, if ai=3, acsr is 03
%%%%%%%%%%%
binfile = [binPath,'\a',acsr,'_s',susr,'_e',exsr,'_depth.bin'];
if ~exist(binfile,'file');
disp('error');
continue;
end;
disp(binfile);
fileread = fopen(binfile);
if fileread<0
disp('no such file.');
return;
end
header = fread(fileread,3,'uint=>uint');
nnof = header(1); ncols = header(2); nrows = header(3);
depths = zeros(ncols, nrows, nnof);
for f = 1:nnof
frame = zeros( ncols, nrows);
for row = 1:nrows
tempRow = fread(fileread, ncols, 'uint=>uint');
tempRowID = fread(fileread, ncols, 'uint8');%%%%%
frame(:,row) = tempRow;
end
depth(:,:,f) = frame;
clear tempRow tempRowID;
end
fclose(fileread);
end
end
end
end
  1 件のコメント
Jan
Jan 2016 年 10 月 19 日
The question is not clear. You tell us, that the data is saved as a MAT file, but the code does not create a MAT file. Therefore we cannot see, what is contained in this file. You ask for "header files" but do not explain, which kind of "header files" are meant. The binary files contain a header, as your code shows. This means that some information for the handling of the data is written at the start of the file. In your case it is the number of rows and columns. But this is not a "header file", but a "file header".

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2016 年 10 月 19 日
編集済み: Jan 2016 年 10 月 19 日
I guess - an exact answer is not possible yet:
Simply insert this after the fclose(fileread) command:
save([binfile(1:end-4), '.mat'], 'depth');
  8 件のコメント
preksha pareek
preksha pareek 2017 年 9 月 17 日
Is this provided by signal processing toolbox?
Walter Roberson
Walter Roberson 2017 年 9 月 17 日
No, getsr() is not part of any Mathworks product; it appears to be from the File Exchange contribution that I linked to.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by