Importing DAT file MATLAB

12 views (last 30 days)
Ejay Nsugbe
Ejay Nsugbe on 9 Nov 2020
Commented: Walter Roberson on 9 Nov 2020
Hi guys,
I'm trying to open a DAT file and I came across a rather useful snippet of code as shown below;
[filename, pathname] = uigetfile('*.dat', 'Open file .dat');% only image Bitmap
if isequal(filename, 0) || isequal(pathname, 0)
disp('File input canceled.');
ECG_Data = [];
else
fid=fopen(filename,'r');
end;
time=10;
f=fread(fid,2*360*time,'ubit12');
Orig_Sig=f(1:2:length(f));
plot(Orig_Sig)
The resulting plot looks as though the code has combined and meshed a number of columns together etc. Can anyone advise how I can import bits directly from the columns in the DAT file or best yet open the DAT file in MATLAB?

Answers (1)

Walter Roberson
Walter Roberson on 9 Nov 2020
The .dat file extension is used by many different programs to store data in incompatible formats. You would need to know which program produced the file and have documentation about the file format.
It would be quite unusual for data to be in packed 12 bit values. Not impossible but rarely done. It is a lot more common for 12 bit data to be stored inside 16 bit words, more typically the 12 most significant bits, but sometimes the 12 least significant bits. (You also have to worry about the bit order for packed bits.)
You talk about having meshed a number of columns together, but the way you read the data is only suitable for vector data, for which there would not be any "columns".
  2 Comments
Ejay Nsugbe
Ejay Nsugbe on 9 Nov 2020
Walter, thanks for the reply.
The DAT file contains time-series info. from the monitoring of uterine wall contraction during pregnancy.
I know for certain, it contains signal values as mentioned, but my dillema becomes finding a way of opening the DAT file in MATLAB to extract the relevant data.
Walter Roberson
Walter Roberson on 9 Nov 2020
Not much we as volunteers can do without documentation of the file format.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!