Write the Timetable data to the EDF file
2 Comments
Accepted Answer
Hi @Wensor ,
You asked, “How can I write a Timetable data into a EDF File?”
To address your inquiry regarding writing a Timetable to an EDF file in MATLAB, I broke down your requirements and analyzed the provided code.
Data Structure: You are working with a Timetable (TT) containing signal data. EDF File Format: You are attempting to write this data to an EDF file using the edfwrite function. Error Handling: The error indicates that annotations are expected as a two-column array, but you do not have any annotations to include.
So, to write your Timetable data into an EDF file without annotations, you need to make that the data structure and the header properties are correctly set up based on mathworks documentation provided in the link below.
https://www.mathworks.com/help/signal/ref/edfwrite.html
Below is the complete and corrected code based on your original snippet.
% Create your Timetable data time = duration(0, 0, 0.1*(0:6)'); % Create a duration vector for time data1 = randn(length(time), 1); % Signal 1 data2 = randn(length(time), 1); % Signal 2 data3 = randn(length(time), 1); % Signal 3
% Create a timetable TT = timetable(time, data1, data2, data3);
% Prepare the EDF Header hdr = edfheader("EDF"); hdr.NumSignals = 3; % Number of signals hdr.NumDataRecords = height(TT); % Number of data records hdr.DataRecordDuration = duration(0, 0, 0.1); % Duration of each data record
% Specify signal labels and other properties hdr.SignalLabels = ["Signal 1"; "Signal 2"; "Signal 3"]; hdr.TransducerTypes = ["EEG"; "EEG"; "EEG"]; % Example transducer type hdr.PhysicalDimensions = ["uV"; "uV"; "uV"]; % Signal units hdr.PhysicalMin = [-500; -500; -500]; % Min physical values hdr.PhysicalMax = [500; 500; 500]; % Max physical values hdr.DigitalMin = [-32768; -32768; -32768]; % Min digital values hdr.DigitalMax = [32767; 32767; 32767]; % Max digital values
% Prepare signal data sigdata = [TT.data1, TT.data2, TT.data3]; % Extract signal data from the timetable
% Write to EDF file without annotations edfw = edfwrite("rand.edf", hdr, sigdata); % Correct method call
Please see attached.
If you later decide to include annotations, you would need to create a separate timetable for them, ensuring it contains the required columns: Onset, Annotations, and Duration. Make sure that the length of the sigdata matches the number of data records in the header.
Hope this answers your questions please let me know if you have any further questions.
4 Comments
Hi @Wensor,
I have executed the code above and attached the file below. Please let me know if this answers your question.
More Answers (1)
3 Comments
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!