필터 지우기
필터 지우기

fopen problem help please

조회 수: 12 (최근 30일)
Anton Gubrienko
Anton Gubrienko 2021년 4월 15일
댓글: Ankriti Sachan 2021년 4월 20일
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
Stephen23
Stephen23 2021년 4월 15일
@Anton Gubrienko: please show the complete error message. This means all of the red text.
Walter Roberson
Walter Roberson 2021년 4월 15일
I suspect that your filename variable is a cell array instead of a character vector or string scalar

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

답변 (1개)

Ankriti Sachan
Ankriti Sachan 2021년 4월 20일
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.
I hope this answers your query.
  댓글 수: 4
Walter Roberson
Walter Roberson 2021년 4월 20일
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
Warning: failed to open file because: "Is a directory
[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
Warning: failed to open file because: "No such file or directory
[fid, msg] = fopen({'junk_does_not_exist_for_test'});
Error using fopen
First input must be a file name or a file identifier.
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
Ankriti Sachan 2021년 4월 20일
Sure, thanks for clarifying. That helps.

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

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by