fopen problem help please
Ältere Kommentare anzeigen
In this part of code
disp(filename)
fid=fopen([filename '.hea']);
disp('debug')
I have error
---WFDB/I0005 ->(its a display filename, i have in WFDB folder files I0005.hea and i0005.mat)
---Error using fopen
---First input must be a file name or a file identifier.
Please, help with fopen) (m2020 mac version)
2 Kommentare
Stephen23
am 15 Apr. 2021
@Anton Gubrienko: please show the complete error message. This means all of the red text.
Walter Roberson
am 15 Apr. 2021
I suspect that your filename variable is a cell array instead of a character vector or string scalar
Antworten (1)
Ankriti Sachan
am 20 Apr. 2021
0 Stimmen
As Walter mentioned, I am also guessing that you are providing a folder name instead of a filename as the input to the fopen function. Please verify the same. Also, you can verify if any other file in the same folder is accessible using fopen.
Also, if you are trying to read the physionet data, please refer to the answer here - https://in.mathworks.com/matlabcentral/answers/528018-how-can-i-create-a-vector-from-one-specific-data-in-552-hea-files-in-matlab.
I hope this answers your query.
4 Kommentare
Walter Roberson
am 20 Apr. 2021
It is unlikely that a name ending in .hea is a directory name. Not out of the question, but not likely.
Ankriti Sachan
am 20 Apr. 2021
Bearbeitet: Ankriti Sachan
am 20 Apr. 2021
Hi Walter, yes, even I believe .hea is not a directory name. However, I read a few resources that indicate that the filenames and the path provided might be incorrect for fopen() here. It might be a possibility that the path provided might be level below to the actual path where the files are located.
Also, I came across this answer - https://in.mathworks.com/matlabcentral/answers/83546-how-to-read-file-100-dat-and-100-atr-of-mit-bih-database-physionet.
It seems like the .dat and .atr files are also read in the same way as the .hea files. Also, there are few comments that talk about reading these files in this post. Maybe those can help.
First input must be a file name or a file identifier
You do not get that message if you accidentally name a directory instead of a file.
mkdir junk_dir_for_test
[fid, msg] = fopen('junk_dir_for_test');
if fid < 0
warning('failed to open file because: "%s', msg);
else
fprintf('fopen of directory worked?\n');
fclose(fid)
end
[fid, msg] = fopen('junk_does_not_exist_for_test');
if fid < 0
warning('failed to open file because: "%s', msg);
else
fprintf('fopen of non-existent file worked?\n');
fclose(fid)
end
[fid, msg] = fopen({'junk_does_not_exist_for_test'});
if fid < 0
warning('failed to open file named as cell because: "%s', msg);
else
fprintf('fopen of non-existent named as cell file worked?\n');
fclose(fid)
end
The only case you get the error message being observed is if the parameter passed to fopen() is not a character vector or string scalar.
In the context of
% fid=fopen([filename '.hea']);
then if filename were a cell array of character vectors instead of a character vector, you would get that problem.
Ankriti Sachan
am 20 Apr. 2021
Sure, thanks for clarifying. That helps.
Kategorien
Mehr zu File Operations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!