not able to load .dat file in matlab

1,682 views
Skip to first unread message

Anwesha

unread,
Apr 26, 2018, 7:09:46 AM4/26/18
to Open Ephys
Hello,
I am trying to load a .dat file of the Intan system through matlab and not able to do so. The dat file contains all strange characters and MATLAB is giving me an error everytime. 
Error using load
Unknown text on line number 1 of ASCII file
C:\Users\anwesha\Desktop\26_180426_114006\amp-A-016.dat
"ÿ".

Can anyone help me with this problem. I googled online but non of the solutions are helpful for me.

Thanks,
A

Aarón Cuevas

unread,
Apr 26, 2018, 2:46:09 PM4/26/18
to Open Ephys
Hello Anwesha,

The load command from MATLAB can only read files in either MATLAB's proprietary .mat format or in plain text. The .dat generated by the binary writer are in plain binary format, containing a raw array of 16 bit integers.
To load them, you could do something like this:

f=fopen('amp-A-016.dat','rb');
D=fread(f,[nChannels, Inf],'int16');
fclose(f);

where nChannels contains the number of recorded channels. That should load the array into the D variable.

Best,
Aarón

Sergio Martínez-Bellver

unread,
Aug 16, 2018, 12:32:43 PM8/16/18
to Open Ephys
 Hi Aarón,

I tried your code with a 45min 45ch recording (7.5gb) and it's giving me some memory issues.

Obviously, I should split the reading of the file but I'm having some problems with that too in specifying the m-n dimension of the reading.

Could you please extend a bit your help or suggest another method (software, conversion to other formats readable by Matlab)?

Thanks in advance, 
Sergio

Aarón Cuevas

unread,
Aug 16, 2018, 8:33:04 PM8/16/18
to Open Ephys
Hello Sergio,

Unless you have lots of ram, trying to load so much data at once will cause you trouble no matter the format.
The fread dimensions are [nChannels nSamplesToRead].
Additionally, each time you execute a fread command it will start from where it stopped last time, so you can issue multiple freads to load different chunks of data.
An example could be something like:

f=fopen('filename', 'rb');
while (~feof(f)) %tests for end of file 
D=fread(f,[nChannels, nSamplesToRead],'int16');
process_your_data(D);
end
fclose(f);

Or, if you wanted to start from a specific offset you could use the fseek function, which moves the read pointer a specific number of bytes
f=fopen('filename', 'rb');
fseek(f, nChannels*nOffsetSamples*2); %a int16 is 2 bytes
D=fread(f,[nChannels, nSamplesToRead],'int16');
fclose(f);

I hope this clarifies it for you. I'll be happy to offer further explanations if you need them

Best,
Aarón

Sergio Martínez-Bellver

unread,
Aug 24, 2018, 3:07:42 AM8/24/18
to Open Ephys

Thanks a lot Aarón!

It worked nice.

Best,

Sergio
Reply all
Reply to author
Forward
0 new messages