open a list fo file with fopen???

3 ビュー (過去 30 日間)
Pachira85
Pachira85 2016 年 10 月 22 日
コメント済み: Image Analyst 2016 年 10 月 22 日
It gives problem for the fileID.
File_info = dir('*.lis');
filename = {File_info.name};
[m,nfile]= size(filename);
for ifile= 1:nfile
delimiter = {' ',';'};
formatSpec = '%s%s%s%s%s%s%[^\n\r]';
fileID=fopen(filename{ifile}, 'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'MultipleDelimsAsOne', true, 'ReturnOnError', false);
fclose(fileID);
end
  3 件のコメント
Pachira85
Pachira85 2016 年 10 月 22 日
ok. Sorry. But in the link there is not the solution of my problem
Image Analyst
Image Analyst 2016 年 10 月 22 日
Well it was a step along the way. I'm sure there was something in there about attaching your data so people can reproduce your situation. I guess you didn't read it because you didn't attach the file. You didn't even attach all the red text of your error message like I asked directly in the comment. Did you even look at all I could do (given what you've provided) in my answer below? Come on, make it easy for us to help you not hard.

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

回答 (1 件)

Image Analyst
Image Analyst 2016 年 10 月 22 日
Here's some improved code:
delimiter = {' ',';'};
formatSpec = '%s%s%s%s%s%s%[^\n\r]';
File_info = dir('*.lis');
allFileNames = {File_info.name};
[m,nfile]= size(allFileNames)
numFilesProcessed = 0;
for ifile= 1:nfile
thisFileName = fullfile(pwd, allFileNames{ifile});
fprintf('Processing %s\n', thisFileName);
fileID=fopen(allFileNames{ifile}, 'r');
if fileID ~= -1
% File is good.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'MultipleDelimsAsOne', true, 'ReturnOnError', false);
fclose(fileID);
numFilesProcessed = numFilesProcessed + 1;
else
message = sprintf('Cannot open this file:\n%s', thisFileName);
uiwait(warndlg(message));
end
end
fprintf('Done!\nProcessed %d files.\n', numFilesProcessed);

カテゴリ

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