Keep getting an error with my function regarding textscan()

2 ビュー (過去 30 日間)
louis beauregard
louis beauregard 2017 年 2 月 18 日
コメント済み: louis beauregard 2017 年 2 月 19 日
I'm trying to import a text file as a 2 row vector and keep getting this back,
Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in importfile (line 36)
textscan(fileID, '%[^\n\r]', startRow(1)-1, 'WhiteSpace', '', 'ReturnOnError', false);

回答 (2 件)

Image Analyst
Image Analyst 2017 年 2 月 18 日
When you used fopen(), it probably returned an invalid file handle, like the file doesn't exist, is locked, or is readonly. Did you check the value of fileID that fopen returned? You forgot to show us the fopen() line of code.
  4 件のコメント
Walter Roberson
Walter Roberson 2017 年 2 月 19 日
The apparent use of IMPORTFILE was because the code was not formatted :(
Walter Roberson
Walter Roberson 2017 年 2 月 19 日
The file might have been present before in the current directory, but that does not mean that it is present now in any directory, let alone the current directory.

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


louis beauregard
louis beauregard 2017 年 2 月 19 日
the fileId is -1
  2 件のコメント
Walter Roberson
Walter Roberson 2017 年 2 月 19 日
Change the line
fileID = fopen(filename,'r');
to
[fileID, msg] = fopen(filename,'r');
if fileID < 0
error('Failed to open file "%s" because: "%s"', filename, msg);
end
louis beauregard
louis beauregard 2017 年 2 月 19 日
lol i ended up going into the file directory and changing them to .txt and it worked but thanks for the help

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

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by