Error using edfinfo Expected input to be integer-valued.

조회 수: 6 (최근 30일)
Nada Maarouf
Nada Maarouf 2023년 11월 28일
댓글: Walter Roberson 2023년 11월 29일
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개)

Image Analyst
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
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
Walter Roberson 2023년 11월 29일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 EEG/MEG/ECoG에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by