my text file is always not opened when i use fopen!!

6 ビュー (過去 30 日間)
yousef albah
yousef albah 2017 年 9 月 4 日
コメント済み: Stephen23 2017 年 9 月 4 日
I am trying to use a fopen command on matlab on a text file, but it always give me a value of -1. and when i try to continue to use textscan it wont let do the work

採用された回答

Jan
Jan 2017 年 9 月 4 日
編集済み: Jan 2017 年 9 月 4 日
If fopen cannot open the file, it is either not existing or there is another bug in your code. Check the existence at first:
exist(FileName, 'file')
Do you use an absolute path or rely on the current folder, which could be change by a timer or GUI callback unexpectedly? Prefer absolute paths containing the folder, because this is much safer.
If this does not help, post the relevant part of the code here.
It is useful to display the error message created by fopen:
[fileID, errmsg] = fopen(FileName);
if fileID == -1
error(['Cannot open file: %s', char(10), '%s', errmsg);
end
  1 件のコメント
Stephen23
Stephen23 2017 年 9 月 4 日
Note that both error and assert accept an fprintf-style format string:
[fileID, errmsg] = fopen(FileName);
assert(fileID>=3,'Cannot open file:\n%s',errmsg)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-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