Open multiple file as string
古いコメントを表示
Hi guys,
I have a question.
I have different file like string, and I want to open it togheter, without write the name
I tryd this code, but in this way I have to write the name of single file.
Have you advice about it?
directory='D:\Documents\numeric\pip\';
fittingresultspath = 'D:\Documents\numeric\fitting_results\pip\';
fid = -1; msg = ''; while fid < 0
disp(msg); filename = input('input: ','s'); fid=1;
end
Thank you so much
8 件のコメント
Geoff Hayes
2020 年 4 月 10 日
FC - do you want to keep prompting the user for a file (to read) until the file can be opened?
msg = '';
while fid < 0
disp(msg);
filename = input('input: ','s');
fid=fopen(filename, 'r');
end
% do something with the file
% close the file
fclose(fid);
Fredic
2020 年 4 月 11 日
Geoff Hayes
2020 年 4 月 11 日
FC - you'll need to open the files one by one possibly with a loop. I don't understand why you'd want to open them all at once. Also, what do you mean by series of files like string?
Fredic
2020 年 4 月 11 日
Geoff Hayes
2020 年 4 月 11 日
I'm not really sure what you mean by for a series of files "s" string. What happens when you try something like
while true
filename = input('please input a file name: ','s');
fid=fopen(filename, 'r');
if fid > 0
% do something with file
% close file
fclose(fid);
else
fprintf('Could not open file %s\n', filename);
end
response = input('Are you finished (Y/N): ','s');
if strcmpi(response,'Y')
break;
end
end
Fredic
2020 年 4 月 11 日
Geoff Hayes
2020 年 4 月 11 日
Fredic
2020 年 4 月 12 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Debugging and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!