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

39 views (last 30 days)
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 Comment
Jan
Jan on 19 Oct 2016
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".

Sign in to comment.

Answers (1)

Jan
Jan on 19 Oct 2016
Edited: Jan on 19 Oct 2016
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 Comments
Walter Roberson
Walter Roberson on 17 Sep 2017
No, getsr() is not part of any Mathworks product; it appears to be from the File Exchange contribution that I linked to.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!