Error using edfinfo Expected input to be integer-valued.
2 次查看(过去 30 天)
显示 更早的评论
Hi
I have an edf file that contains EEG data that is too large and I therefore need to split it in three to use it in my project.
I have a code that succesfully split the file into three parts, however when I want to check the info about one of the new files, I start getting errors.
This is the code:
inputFile = '452F_(1).edf';
outputFile1 = '452F_part1.edf';
outputFile2 = '452F_part2.edf';
outputFile3 = '452F_part3.edf';
numParts = 3;
% Open the input file for reading
fidInput = fopen(inputFile, 'rb');
% Open the output files for writing
fidOutput1 = fopen(outputFile1, 'wb');
fidOutput2 = fopen(outputFile2, 'wb');
fidOutput3 = fopen(outputFile3, 'wb');
%copy of header
headerBytes = 256 * numParts;
headerData = fread(fidInput, headerBytes, '*uint8');
fwrite(fidOutput1, headerData);
fwrite(fidOutput2, headerData);
fwrite(fidOutput3, headerData);
% calculate the size of each part
fileSize = dir(inputFile).bytes - headerBytes;
partSize = fileSize / numParts;
for part = 1:numParts
% calculate the range of bytes to read for this part
startByte = headerBytes + (part - 1) * partSize + 1;
endByte = min(headerBytes + part * partSize, fileSize + headerBytes);
% Set the position in the input file
fseek(fidInput, startByte, 'bof');
% Read and write data
data = fread(fidInput, endByte - startByte + 1, '*uint8');
switch part
case 1
fwrite(fidOutput1, data);
case 2
fwrite(fidOutput2, data);
case 3
fwrite(fidOutput3, data);
end
end
fclose(fidInput);
fclose(fidOutput1);
fclose(fidOutput2);
fclose(fidOutput3);
The errors I get when I want to check the info about one of the new files :
Error in signal.internal.edf.validateEDF (line 43)
validateattributes(numSamples, {'numeric'}, {'integer'}, mfile);
Error in signal.internal.edf.edfinfo (line 27)
signal.internal.edf.validateEDF(filename, fileInfo, version,...
Error in edfinfo/readHeader (line 212)
~, ~] = signal.internal.edf.edfinfo('edfinfo', fid, ...
Error in edfinfo (line 173)
obj = readHeader(obj, filename, fid, fileInfo);
I don't know what to do. If there is a better code to use for splitting please help me, otherwise help me solve the issue.
Thanks
[EDIT - formatted as code.]
1 个评论
Walter Roberson
2023-11-28
编辑:Walter Roberson
2023-11-29
https://www.edfplus.info/specs/edf.html has the file format specifications
回答(1 个)
Image Analyst
2023-11-28
Just how gigantic is your EEG signal? I can't imagine it would be very big, like more than a few MB or so. Are we talking tens of GB here? Can you attach it with the paperclip icon? Zip it up first into a zip file then attach it.
How did you try to check the info about your output files? Can any other program, other than MATLAB, read your output files?
Why all that complicated code in the loop? I believe fread leaves the pointer just after the last byte it read so why not just simply do fread and fwrite 3 times in 6 lines of code with no loop?
data = fread(fidInput, partSize, '*uint8');
fwrite(fidOutput1, data);
data = fread(fidInput, partSize, '*uint8');
fwrite(fidOutput2, data);
data = fread(fidInput, partSize, '*uint8');
fwrite(fidOutput3, data);
5 个评论
Image Analyst
2023-11-29
I'm not familiar with that format so you're on your own. You should look at the file format specification link @Walter Roberson gave you above in the comments section. You can figure it out and code it up just as well as I could, right? Anyway, I don't have time to delve deeply into it, but you do.
Walter Roberson
2023-11-29
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 EEG/MEG/ECoG 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!