Error using edfinfo Expected input to be integer-valued.

1 visualización (últimos 30 días)
Nada Maarouf
Nada Maarouf el 28 de Nov. de 2023
Comentada: Walter Roberson el 29 de Nov. de 2023
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);
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.
[EDIT - formatted as code.]

Respuestas (1)

Image Analyst
Image Analyst el 28 de Nov. de 2023
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 comentarios
Image Analyst
Image Analyst el 29 de Nov. de 2023
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
Walter Roberson el 29 de Nov. de 2023
The format specification I linked to should make it clear that you cannot just divide the edf file into pieces.
You would probably be better of looping, using edfread with SelectedSignals or SelectedDataRecords and edfwrite the parts.

Iniciar sesión para comentar.


Más información sobre EEG/MEG/ECoG en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by