필터 지우기
필터 지우기

I want my function to return -1 when the file doesn't open.

조회 수: 1 (최근 30일)
Irfan Ibrahim Yeniceri
Irfan Ibrahim Yeniceri 2022년 4월 2일
댓글: Voss 2022년 4월 2일
I want my function to return -1 when the file doesn't open. But this happens

채택된 답변

Voss
Voss 2022년 4월 2일
Your code is explicitly throwing the error, here:
error('error opening file %s\n',fname);
You can remove that line (and the next one because there is no need to close a file that's not open), so that that part looks like this:
if fid < 0
charnum = -1;
return
end
Then the function will return -1 in that case.
  댓글 수: 2
Irfan Ibrahim Yeniceri
Irfan Ibrahim Yeniceri 2022년 4월 2일
Thank you so much. I have been dealing with this for hours. I removed each one individually but i didn't try to removed them both. Thank you again.
Voss
Voss 2022년 4월 2일
You're welcome!

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

추가 답변 (1개)

Riccardo Scorretti
Riccardo Scorretti 2022년 4월 2일
편집: Riccardo Scorretti 2022년 4월 2일
Hi. You must return just after assigning the value -1 to charnum. If you call the function error... well, you get an error message and the program stops. Use warning instead.
if fid == -1
charnum = -1;
warning('error opening file %s', fname);
return
end

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by