TEXTREAD File not found error
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I've been trying to create a loop that will read an arbitrary text file under certain circumstances, but send an error for further prompt if it is not the correct file name (and/or extension).
However, I have the loop running perfectly if the file is there and correctly inputted by the user, if not then it still runs the next bit of the loop (the thank you message) and I get this error:
Error using textread (line 165)
File not found.
Error in Assignment (line 13)
EEGData = textread(Datafile);
My script is:
Datafile=input('Please enter filename with extension: ','s');
if exist ('eegdata.txt', 'file');
disp(sprintf('Thank you, please wait a moment'));
EEGData = textread(Datafile);
else
disp(sprintf('I''m sorry, this file does not exist, try again'))
end
Thanks!
0 件のコメント
採用された回答
Stephen23
2018 年 3 月 11 日
if 2==exist(Datafile, 'file')
6 件のコメント
Stephen23
2018 年 3 月 13 日
編集済み: Stephen23
2018 年 3 月 13 日
Try something like this:
isf = false;
msg = 'enter filename with extension: ';
while ~isf
fnm = input(msg,'s');
isf = 2==exist(fnm,'file');
msg = 'try another filename: ';
end
disp('Thank you, please wait a moment');
EEGData = textread(fnm);
Personally I find throwing an error a better choice.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Adding custom doc についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!