Keep getting an error with my function regarding textscan()
显示 更早的评论
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
2017-2-18
0 个投票
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 个评论
louis beauregard
2017-2-18
编辑:Walter Roberson
2017-2-19
Image Analyst
2017-2-19
OK, but you still have not answered my question "Did you check the value of fileID that fopen returned?" Please answer. What is it?
Also, where is importfile defined? You call it twice, here:
[t,v]=importfile('LA.txt')
%IMPORTFILE Import numeric data from a text file as column vectors. %
[DATETIME2142017602PM,VARNAME2] = IMPORTFILE(FILENAME)
however those are actually different functions because the case of the letters is different and MATLAB is case sensitive. Where is it defined?
Walter Roberson
2017-2-19
The apparent use of IMPORTFILE was because the code was not formatted :(
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
2017-2-19
0 个投票
2 个评论
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
2017-2-19
类别
在 帮助中心 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!