open a list fo file with fopen???

3 次查看(过去 30 天)
Pachira85
Pachira85 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 CenterFile 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!

Translated by