EDF writing - error when using cell array as signal DATA

4 次查看(过去 30 天)
Hello
I would like to do a edf file entering my signals from a cell array. I am doing a practice , mydata is
when I try to do this
>> C = {[1;2;3],[1;2;3;4],[1;2];
[4;5;6],[5;6;7;8],[3;4];
[7;8;9],[9;10;11;12],[5;6];
[10;11;12],[13;14;15;16],[7;8]}
>> hdr = edfheader("EDF");
hdr.NumSignals = 3;
hdr.NumDataRecords = 4;
hdr.DataRecordDuration = duration(0, 0, 1);
hdr.PhysicalMin = [1,1,1];
hdr.PhysicalMax = [12,16,8];
>> edfw = edfwrite('rand.edf',hdr,C);
However, I do get an error
Error using signal.internal.edf.write.validateSignalData
Expected input to be a vector
Error signal.internal.edf.write.getFileCreateOpts>checkSignals (第 223 行)
signal.internal.edf.write.validateSignalData(sigData, ...
Error signal.internal.edf.write.getFileCreateOpts>createHdr (第 96 行)
[reqhdr, sigData] = checkSignals(reqhdr, sigData, tNumSignals);
Error signal.internal.edf.write.getFileCreateOpts>createAndValidateHeader (第 47 行)
[hdr, sigData, tsal] = createHdr(thdr, sigData, tsal, hdrPropertiesList, ...
Error signal.internal.edf.write.getFileCreateOpts (第 13 行)
[hdr, sigData, tsal] = createAndValidateHeader(hdr, sigData, tsal, ...
Error edfwrite/createFile (第 1620 行)
signal.internal.edf.write.getFileCreateOpts(hdr, signalData, ...
Error edfwrite (第 499 行)
[obj, fileInfo] = createFile(obj, filename, hdr,...
Each column of my data represents a signal, and each signal is sampled at a different rate,
because I don't have specific data yet, so I did this exercise.

采纳的回答

Sandeep Mishra
Sandeep Mishra 2024-9-3
Hi Wensor,
I reviewed the code snippet and encountered a similar issue in MATLAB R2023b.
Upon further investigation, I discovered a relevant MATLAB Answers post which addresses a similar error: 
The root cause of this error is related to the input cell array 'C'. When using the edfwrite function, if you specify a cell array as your signal data, each cell must correspond to a single signal.
However, the provided code snippet shows 'C' as a 4x3 cell array, with each cell containing vectors of varying sizes.
To resolve this issue, you can reshape the input signal 'C' to align with the expected format.
Here's a suggested approach:
% Reshaping input cell array C to C_reshaped
C_reshaped = cell(1,3);
for col = 1:3
C_reshaped{col} = vertcat(C{:,col});
end
% Using edfwrite with C_reshaped sigData
edfw = edfwrite('rand.edf',hdr,C_reshaped);
In the above approach, 'C_reshaped' will be a 1x3 cell array, where each column contains the concatenated results of all rows for that column, ensuring the data is structured correctly for edfwrite.
Please refer to the below documentation to learn more about edfwrite’ function in MATLAB: https://www.mathworks.com/help/releases/R2023b/signal/ref/edfwrite.html
I hope this helps!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 AI for Signals 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by