an easy way to read log file by MATLAB

Recommended Posts

Hi everyone,

I found an easy way to read .log file by MATLAB.  MATLAB has functions to read binary file but the difficulty is that we are not sure about the header and format of the log data. I am not familiar with Python so the other way that posted by benl using Python is such a pain to me.

Here are a few lines that can easily decode .log file with two channels of data:


%% Read Data from OpenLogger file
close all;clear;clc
logfilename = '20190723_9_0.log';
finfo = dir(['F:\' logfilename]);
channelNum = 2; %number of channels
sampleNum = finfo.bytes/2/channelNum;
fileID = fopen(logfilename);
logdata = fread(fileID,[channelNum sampleNum],'int16=>int16');
plot(logdata(1,headerNum+1:end),'-'),hold on %channel 1
plot(logdata(2,headerNum+1:end),'-'),hold off %channel 2


WaveForms Live


read in Matlab



Note: I don't care about the header info so I just get rid of it. I use random input pulses for ch2; The two plots are not from the same time.





Share this post

Link to post
Share on other sites

Thanks for posting your code Peggy, Iv'e managed to use it to view some data.

Did you find out any more about what is in the header? Maybe that contains things like number of channels, sample rate etc?


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now