Why I am getting problem with fgets() function in the below code for Seismic Risk Analysis??

I am trying to understand the code written by my professor which is as below :
fileh='input/hist.dat';
LINP = fopen(fileh,'r');
TMP = str2num(fgets(LINP));
In this code, I am getting problem in the 3rd line above stated. The problem or error that the matlab shows is :
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in Haz_example
TMP = str2num(fgets(LINP));
Why I am facing this problem. Please help.

댓글 수: 1

Check the value of LINP ...it should be positive...I suspect, the file is not present in the path where your code is present. Provide the correct path for the file.

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

답변 (2개)

Try modifying your fopen line of code to this:
[LINP,errmsg] = fopen(fileh,'r')
Before running the fgets line of code, check the value of LINP. If it has a value of -1, it couldn't open the file. The errmsg will tell you why.
[LINP,errmsg] = fopen(fileh,'r')
LINP =
-1
errmsg =
'No such file or directory'
madhan ravi
madhan ravi 2018년 12월 24일
Make sure you specify the path of the file when using fopen.

카테고리

도움말 센터File Exchange에서 Seismology에 대해 자세히 알아보기

제품

릴리스

R2017a

질문:

2018년 12월 24일

답변:

2018년 12월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by