open a list fo file with fopen???
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
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
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!