%% Read EDF File into Timetable
% Read data from the EDF file example.edf into a timetable. The file contains two signals, ECG and ECG2. Each signal contains six data records, and each data record has a duration of 10 seconds.

tt = edfread('example.edf')

%
% Create an edfinfo object containing information about example.edf. Verify that the signals have the expected names. Extract the sample rates of the signals using the DataRecordDuration and NumSamples properties of the object.

info = edfinfo('example.edf');

info.SignalLabels
fs = info.NumSamples/seconds(info.DataRecordDuration)

%
% Plot the first record of the first signal. For more information about accessing data in tables, see Access Data in Tables.

recnum = 1;
signum = 1;
t = (0:info.NumSamples(signum)-1)/fs(signum);
y = tt.(signum){recnum};

plot(t,y)
legend(strcat("Record ",int2str(recnum),", Signal ",info.SignalLabels(signum)))
hold on

% Extract and plot the fifth record of the second signal.

recnum = 5;
signum = 2;
t = (0:info.NumSamples(signum)-1)/fs(signum);
y = tt.(signum){recnum};

plot(t,y, ...
    'DisplayName',strcat("Record ",int2str(recnum),", Signal ",info.SignalLabels(signum)))
hold off
xlabel('t (seconds)')

% Copyright 2020 The MathWorks, Inc.