Error using edfinfo Expected input to be integer-valued.

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.]

Answers (1)

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 Comments

The edf files are too large for the website I want to upload them on to be analyzed. They must max be 1250 MiB, and each one of them is 3, something gb.
I tried to check the info about the output file, like I did with the original one:
info = edfinfo('452F_(1).edf');
info.SignalLabels
where "452F_(1).edf" was exchanged with one of the output files.
Honestly, regarding the code, I got some help from my friend, and since it ran and divided the file, I went with it , but it didnt work to upload it on the website. I tried to upload the edf file as a zip-file but it is saying its bigger than 5 MB so it's not working. Also, i attached a pic of the error that occurred on the website. I can share the file with you on google drive or something
It's possible that there is something in the header that says something about the data, like how many total bytes there are after the header, so just copying the original header might not work. You may need to decode the header meta data and correct it to be valid with the new signal length.
Hmm, how do I do that? Now, I substituted the loop in my code with your input, and the first part could be analyzed on the website. However, the same error is occuring when trying to upload part2 and part3. Can you please help me with a code, how to do what u r talking about?
Thanks
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.
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.

Sign in to comment.

Categories

Asked:

on 28 Nov 2023

Commented:

on 29 Nov 2023

Community Treasure Hunt

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

Start Hunting!